如何使用javascript或jquery按钮点击执行ctrl + c或复制commad [英] How to execute ctrl+c or copy commad using javascript or jquery on button click

查看:1914
本文介绍了如何使用javascript或jquery按钮点击执行ctrl + c或复制commad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用点击EVENT执行复制命令?

Is it possible to execute copy command using click EVENT?

我选择了一些文本,我想将此文本复制到 onClick 事件,以便我可以将此文本传递到另一个页面,不要使用右键单击或 CTRL + C 来复制文本。 / p>

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或复制commad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆