【发布时间】:2017-07-04 14:16:44
【问题描述】:
我在 stackoverflow 中尝试了很多解决方案,但都不起作用。(here 和 here)
我在Website 中尝试并使用chrome extension 运行代码(chrome 59.0.3071.104 64bit)
<h4 align="center">text data to copy</h4>
var copy_text = document.getElementsByTagName("h4")[0];
copy_text.select(); //-> error: select is not a function
和
var range = document.createRange();
range.selectNode(copy_text);
window.getSelection().addRange(range);
document.execCommand("copy"); //-> clipboard not change
有什么解决办法吗? 谢谢。
编辑:我认为我的问题是页面加载(安全浏览器),所有解决方案都与用户交互
【问题讨论】:
-
console.log (document.queryCommandSupported('copy')) 这个命令有什么输出?
-
它写“真”
-
你试过this option吗?
-
@Saravana:
window.getSelection().addRange(range);sellect 也成功了。 -
可以销售但不能复制
标签: javascript