我使用FETCH获取一些文本并将此文本放入TextArea,然后我选择文本并试图复制它,但它没有用,以下是我的代码:
const copy_text_from_file = (filename) => {
fetch('/texts/show/?filename=' + filename, {
credentials: 'include'
}).then(function(response) {
return response.json();
}).then(function(json) {
const textarea = document.getElementById('clipboard');
textarea.focus();
textarea.innerHTML = json.content;
textarea.select();
console.log( document.execCommand('copy') ); // writes false to console
});
};
发布于 2018-07-26 16:37:49
document.execCommand('copy')只有在受信任的用户操作(如单击事件)时才能工作
https://stackoverflow.com/questions/-100005807
复制相似问题