Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
498 views
in Technique[技术] by (71.8m points)

javascript - 从浏览器复制到剪贴板时,如何在HTML中保留数据属性(Javascript - How to preserve data attribute in the HTML when copy from browser to clipboard)

When copy from browser, I want to add data attribute to the copied content(HTML) so that when the content is pasted into my application, I can retrieve the data attribute in the HTML.

(从浏览器复制时,我想将数据属性添加到复制的内容(HTML)中,以便在将内容粘贴到应用程序中时,可以在HTML中检索数据属性。)

I've tried adding the data attribute to the first element in the selection range, however it doesn't seem to always work in Chrome since Chrome doesn't always preserve the data attribute in the selected HTML when setting it to clipboard.

(我尝试将data属性添加到选择范围内的第一个元素,但是由于Chrome并不总是将data属性设置为剪贴板时将其保留在所选HTML中,因此它似乎并不总是在Chrome中起作用。)

My questions is how to reliably set data attribute to the selected HTML so that it is always preserved when copied to Clipboard.

(我的问题是如何可靠地将数据属性设置为选定的HTML,以便在复制到剪贴板时始终保留该属性。)

I don't want to override the default browser Clipboard action because it is hard to keep the copied content exactly the same(including styles).

(我不想覆盖默认的浏览器剪贴板动作,因为很难使复制的内容完全相同(包括样式)。)

Any help is appreciated.

(任何帮助表示赞赏。)

  ask by Kylin Li translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...