我在 stackoverflow 中尝试了很多解决方案,但它不起作用。(这里和这里)
我在网站中尝试并使用chrome 扩展来运行代码(chrome 59.0.3071.104 64位)
<h4 align="center">text data to copy</h4>
var copy_text = document.getElementsByTagName("h4")[0];
copy_text.select(); //-> error: select is not a function
Run Code Online (Sandbox Code Playgroud)
和
var range = document.createRange();
range.selectNode(copy_text);
window.getSelection().addRange(range);
document.execCommand("copy"); //-> clipboard not change
Run Code Online (Sandbox Code Playgroud)
有什么解决办法吗?谢谢。
编辑:我认为我的问题是页面加载(安全浏览器),所有解决方案都与用户交互一起使用
javascript ×1