“显示:无” 内容已复制到剪贴板,粘贴时可见

发布于 2024-07-16 22:59:05 字数 580 浏览 6 评论 0 原文

我遇到了将未显示的 HTML 元素复制到剪贴板,然后在将内容粘贴到 MS Word、Outlook 等中时显示的问题。

例如:

<p>Hello</p>
<p style="display: none;">I'm Hidden</p>
<p>World</p>

如果我在浏览器中查看该 HTML,请将文本复制到我的剪贴板,然后粘贴到 Outlook 中,中间段落保持隐藏状态。 好消息。

但是,在此示例中:

<p>Hello</p>
<input type="text" value="I'm not hidden" style="display: none;" />
<p>World</p>

如果我执行相同操作 - 复制到剪贴板,粘贴到 Outlook 中 - 文本输入可见。

有什么办法可以抑制这种情况吗? (无需告诉用户在 Outlook 中选择“仅保留文本”。)

谢谢!

I'm having a problem with non-displayed HTML elements being copied to the clipboard, and then displayed when the content is pasted into MS Word, Outlook, etc.

For example:

<p>Hello</p>
<p style="display: none;">I'm Hidden</p>
<p>World</p>

If I view that HTML in a browser, copy the text to my clipboard, then paste into Outlook, the middle paragraph remains hidden. Good news.

However, in this example:

<p>Hello</p>
<input type="text" value="I'm not hidden" style="display: none;" />
<p>World</p>

If I do the same - copy to clipboard, paste into Outlook - the text input is visible.

Is there any way I can supress this? (Without resorting to telling users to select "Keep text only" in Outlook.)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

锦爱 2024-07-23 22:59:05

听起来您需要让 JavaScript 创建 DOM 部分,而不仅仅是更改 CSS 样式。 不要更改“我隐藏”段落的显示属性,而是让 JavaScript 在您希望显示该元素时创建该元素,并在您希望隐藏它时将其删除。

如果元素足够复杂,那么也许您可以使用“display:none”将它们放在文档的底部,然后将它们移动到您希望它们可见的位置。

It sounds like you need to have the JavaScript create the DOM sections rather than just changing CSS styles. Instead of changing the display property of the "I'm hidden" paragraph, have the JavaScript create that element when you want it to display, and remove it whan you want to hide it.

If the elements are complicated enough, then perhaps you can have them at the bottom of the document with "display:none", but then move them into the place where you want them visible.

暖树树初阳… 2024-07-23 22:59:05

使用 type='hidden' 而不是 type='text' 作为输入框,并将其包装在 div 中,样式设置为 display: none

Use type='hidden' instead of type='text' for the input box and wrap this inside a div with style set to display: none

栩栩如生 2024-07-23 22:59:05

您应该知道,仅当渲染器支持所有 CSS 样式时,使用 CSS 隐藏 HTML 才有效。

仅仅因为您在 Outlook 中没有看到复制/粘贴的 HTML,并不意味着数据不存在。

我不确定您实际上想要实现什么:为什么您需要用户将 HTML 复制到 Outlook 中?

You should be aware that hiding HTML with CSS only works if the renderer supports all the CSS styles.

Just because you do not see copy/pasted HTML in Outlook does not mean the data is not already there.

I am not sure what you are actually trying to achieve: Why do you need your users to copy HTML into Outlook at all?

最美不过初阳 2024-07-23 22:59:05

如果您要求用户复制内容,我建议将该内容放入

If you require users to copy content, I'd recommend dropping that content in a <textarea /> and allowing them to select/copy by clicking a button. It can be difficult to select exactly the right text in browsers.

以可爱出名 2024-07-23 22:59:05

这是我用来解决这个问题的解决方案。

策略:

  1. 当你删除一个元素时生成一个唯一的数字,
  2. 用一个新的 div(又名:替换 div)替换 DOM 中的元素,假设我们知道上一步中生成的唯一数字,我们就能够找到该 ID 。
  3. 向元素添加一个属性,以便当我们稍后看到它时,我们可以提取唯一编号,
  4. 将元素移动到在变量中声明的 div 中,以将其从文档中完全删除。
  5. 当我们想要将元素移回来时,我们只需从属性中获取唯一的编号,找到我们留下的替换 div 并将其替换为原始元素。

以下是一些注意事项:

  1. 我使用lideUp()和slideDown()来动画删除,但您可以根据需要替换这些调用。
  2. 我将 div 元素中的元素放入变量中。 您可以选择将其移至 DOM 中的其他位置,但我希望将其完全删除。 您也可以将其放入变量或数组中。 我使用 div 变量的原因是我希望能够在其上使用 jQuery 的 DOM 搜索,但我不希望它出现在 DOM 中。 例如,我可以这样做:whereHiddenThingsLive.find('.some-class')

代码:

var whereHiddenThingsLive = $('<div></div>');
var nextNum = 0;

function hideElement(element) {
    if (element.hasClass('sop-showing')) {
        element.finish();
    }
    if (element.is(':hidden') || element.hasClass('sop-hiding')) return;
    var num = nextNum++;
    element.addClass('sop-hiding');
    element.slideUp(400, function () {
        var replacer = $('<div class="hide-replacer" style="display:none;"></div>').prop('id', 'hide-replacer-' + num);
        element.prop('replaced-by', num);
        element.after(replacer);
        element.appendTo(whereHiddenThingsLive);
        element.removeClass('sop-hiding');
    });
}

function showElement(element) {
    if (element.hasClass('sop-hiding')) {
        element.finish();
    }
    if (element.is(':visible') || element.hasClass('sop-showing')) return;
    element.addClass('sop-showing');
    var num = element.prop('replaced-by');
    element.detach();
    element.removeProp('replaced-by');
    $('#hide-replacer-' + num).after(element).remove();
    element.slideDown(400, function() {
        element.removeClass('sop-showing');
    });
}

Here is the solution I used to work around it.

The strategy:

  1. generate a unique number when you remove an element
  2. replace element in the DOM with a new div (aka: the replacer div) with an ID which we will be able to find given that we know the unique number generated in the last step.
  3. add a property to the element so that when we see it later we can extract the unique number
  4. move the element into a div which is declared in a variable to remove it from the document completely.
  5. When we want to move the element back we simply get the unique number from the property, locate the replacer div we left behind and replace it with the original element.

Here are some notes:

  1. I used slideUp() and slideDown() to animate the removal, but you can replace those calls as you see fit.
  2. I put the elements in a div element in a variable. You could choose to move it somewhere else in the DOM, but I wanted it completely removed. You could also just put it in a variable or an array. The reason I used a div variable is I wanted to be able to use jQuery's DOM search on it, but I didn't want it in the DOM. For example, I can do: whereHiddenThingsLive.find('.some-class').

The code:

var whereHiddenThingsLive = $('<div></div>');
var nextNum = 0;

function hideElement(element) {
    if (element.hasClass('sop-showing')) {
        element.finish();
    }
    if (element.is(':hidden') || element.hasClass('sop-hiding')) return;
    var num = nextNum++;
    element.addClass('sop-hiding');
    element.slideUp(400, function () {
        var replacer = $('<div class="hide-replacer" style="display:none;"></div>').prop('id', 'hide-replacer-' + num);
        element.prop('replaced-by', num);
        element.after(replacer);
        element.appendTo(whereHiddenThingsLive);
        element.removeClass('sop-hiding');
    });
}

function showElement(element) {
    if (element.hasClass('sop-hiding')) {
        element.finish();
    }
    if (element.is(':visible') || element.hasClass('sop-showing')) return;
    element.addClass('sop-showing');
    var num = element.prop('replaced-by');
    element.detach();
    element.removeProp('replaced-by');
    $('#hide-replacer-' + num).after(element).remove();
    element.slideDown(400, function() {
        element.removeClass('sop-showing');
    });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文