“显示:无"内容复制到剪贴板,粘贴时可见 [英] "display:none" content copied to clipboard, visible when pasted

查看:31
本文介绍了“显示:无"内容复制到剪贴板,粘贴时可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,将未显示的 HTML 元素复制到剪贴板,然后在将内容粘贴到 MS Word、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.

例如:

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

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

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.

但是,在这个例子中:

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

如果我也这样做 - 复制到剪贴板,粘贴到 Outlook - 文本输入 可见.

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

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

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

谢谢!

推荐答案

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

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.

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

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.

这篇关于“显示:无"内容复制到剪贴板,粘贴时可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆