How to execute ctrl+c or copy commad using javascript or jquery on button click(如何在单击按钮时使用 javascript 或 jquery 执行 ctrl+c 或复制逗号)
问题描述
是否可以使用click EVENT执行复制命令?
Is it possible to execute copy command using click EVENT?
我选择了一些文本,我希望在 onClick
事件上复制该文本,这样我就可以在不使用右键单击或 CTRL<的情况下将该文本粘贴到另一个页面/kbd>+C 复制文本.
I have some text selected and I want this text to be copied on onClick
event, so that I am able to past this text to another page with out using right click or CTRL+C to copy the text.
推荐答案
function copyText(){
var txt = '';
if (window.getSelection)
txt = window.getSelection();
else if (document.getSelection)
txt = document.getSelection();
else return;
document.getElementById("a").value=txt;
allCopied =document.getElementById("a").createTextRange();
allCopied.execCommand("RemoveFormat");
allCopied.execCommand("Copy");
}
但出于安全原因,大多数浏览器都不允许修改剪贴板( Internet explorer除外).
but for security reasons most browsers do not allow to modify the clipboard( except Internet explorer).
这篇关于如何在单击按钮时使用 javascript 或 jquery 执行 ctrl+c 或复制逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!