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 或复制逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在单击按钮时使用 javascript 或 jquery 执行 c


基础教程推荐
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01