讨逆猴子剪切板,复制失败?
问题:本地开发情况下可以直接复制,公网就不行了…触发了安全机制。
const link = `内容`;
navigator.clipboard.writeText(link);
报错:
解决方案:
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(link);
this.$message.success('链接已复制到剪贴板');
} else {
// document.execCommand('copy') 向剪贴板写文本
let input = document.createElement('input')
input.style.position = 'fixed'
input.style.top = '-10000px'
input.style.zIndex = '-999'
document.body.appendChild(input)
input.value = link
input.focus()
input.select()
let result = document.execCommand('copy');
document.body.removeChild(input);
this.$message.success('链接已复制到剪贴板');
}
标签:style,浏览器,clipboard,link,剪切板,input,navigator,document,讨逆
From: https://blog.csdn.net/weixin_52236586/article/details/140726377