本文介绍了删除用于复制+粘贴的RTF格式?(跨浏览器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定Java修复程序或CSS修复程序是否可以在我的网站上解决此问题.这似乎只发生在Chrome上(目前还不确定IE).

I'm not sure whether a Javascript or CSS fix could fix this issue on my site. This seems to only happen with Chrome (not sure about IE, yet).

每当用户从我的AspDotNetStorefront网站复制文本并将其粘贴到Word文档上时,粘贴的文本就会包含灰色背景.我可以在我的网站上采取什么措施来防止将此RTF格式粘贴功能粘贴到文档上?

Whenever a user copies text from my AspDotNetStorefront site and paste it onto a Word document, the pasted text includes a gray background. Is there anything I can do on my site to prevent this rich text formatting paste feature onto documents?

除了Microsoft Word的默认粘贴设置外,我不确定这是什么原因.

I'm not sure what would be the cause of this besides Microsoft Word's default paste setting.

推荐答案

您可以拦截复制事件,获取没有样式的选择,然后将其放入剪贴板.

You can intercept the copy event, get the selection without style, and put that into the clipboard.

document.addEventListener('copy', function(e) {
  const text_only = document.getSelection().toString();
  const clipdata = e.clipboardData || window.clipboardData;  
  clipdata.setData('text/plain', text_only);
  clipdata.setData('text/html', text_only);
  e.preventDefault();
});

这篇关于删除用于复制+粘贴的RTF格式?(跨浏览器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 17:29