具体实现的JS代码如下:
window.copyToClipboard = function(text) {
// IE specific
if (window.clipboardData && window.clipboardData.setData) {
return clipboardData.setData(\"Text\", text);
}
// all other modern
target = document.createElement(\"textarea\");
target.style.position = \"absolute\";
target.style.left = \"-9999px\";
target.style.top = \"0\";
target.textContent = text;
document.body.appendChild(target);
target.focus();
target.setSelectionRange(0, target.value.length);
// copy the selection of fall back to prompt
try {
document.execCommand(\"copy\");
target.remove();
console.log(\'Copied to clipboard: \"\'+text+\'\"\');
} catch(e) {
console.log(\"Can\'t copy string on this browser. Try to use Chrome, Firefox or Opera.\")
window.prompt(\"Copy to clipboard: Ctrl+C, Enter\", text);
}
}
继续阅读与本文标签相同的文章
上一篇 :
Google I/O:酷科技将拉平这个世界
下一篇 :
拨开区块链的云雾,攻破三元悖论的不可能
-
他让我国芯片研究停滞13年,还骗走11亿研发资金,现状如何?
2026-05-14栏目: 教程
-
健乐教学机器人可开展的教学实训内容
2026-05-14栏目: 教程
-
5G套餐曝光遭“吐槽”,iphone11受追捧,导致苹果11销量比较高
2026-05-14栏目: 教程
-
为什么修电脑的叫自己不要杀毒和清理垃圾?
2026-05-14栏目: 教程
-
当水乡建筑遇上机器人,成就乌镇又一网红景点
2026-05-14栏目: 教程
