JS copies content to the clipboard in the instance code of of compatible with IE and firefox

  • 2020-03-29 23:51:52
  • OfStack


<mce:script type="text/javascript"><!--
function copyToClipboard(meintext)
{
    //ie
    if (window.clipboardData){
        window.clipboardData.setData("Text", meintext);
    }
    else if (window.netscape)
    {
        try
        {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        }
        catch(e)
        {
            alert(" Rejected by browser! "); ///n please type 'about:config' in the browser address bar and press enter /n and then set 'allot.apen.codebase_principal_support' to 'true'
        }
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip) return;
        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if (!trans) return;
        trans.addDataFlavor('text/unicode');
        var str = new Object();
        var len = new Object();
        var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
        var copytext=meintext;
        str.data=copytext;
        trans.setTransferData("text/unicode",str,copytext.length*2);
        var clipid=Components.interfaces.nsIClipboard;
        if (!clip) return false;
        clip.setData(trans,null,clipid.kGlobalClipboard);
    }
    alert(" A link to this page has been copied , You can use Ctrl+V After the paste , Send to a friend !");
    return false;
}
// --></mce:script>
 call copyToClipboard(meintext) ; 
meintext Is the incoming parameter. 
<input id='a' name='a' type='text'value='good' />
<input name="" type="button" value=' copy ' onClick="copyToClipboard(a.value)">
<a href="ums://aHR0cDovLzMyLmRjLmZ0bi5xcS5jb20vZnRuX2hhbmRsZXIvY2E1NGY4YzE3NTI5MzNiNzQ2NjU5ZmVmZjliNTUwZTM0NWNkMTVhNDg1Nzc4ODg5N2MxMWUyMjcwZDE3YjcxMGMwZGUxMmJlMGEyZTVhM2E1MTExMmE1Y2FlOTNmYjkwMGIxNmFkZWVjOGZiYmMxNThlNzg1YTRmNWRjMDdmZGIvQkJDJUU4JTkzJTlEJUU4JTg5JUIyJUU2JTk4JTlGJUU3JTkwJTgzMDgucmFyJjhjZDA3ZTUz" mce_href="ums://aHR0cDovLzMyLmRjLmZ0bi5xcS5jb20vZnRuX2hhbmRsZXIvY2E1NGY4YzE3NTI5MzNiNzQ2NjU5ZmVmZjliNTUwZTM0NWNkMTVhNDg1Nzc4ODg5N2MxMWUyMjcwZDE3YjcxMGMwZGUxMmJlMGEyZTVhM2E1MTExMmE1Y2FlOTNmYjkwMGIxNmFkZWVjOGZiYmMxNThlNzg1YTRmNWRjMDdmZGIvQkJDJUU4JTkzJTlEJUU4JTg5JUIyJUU2JTk4JTlGJUU3JTkwJTgzMDgucmFyJjhjZDA3ZTUz" onClick="copyToClipboard(this.href)">01 set </a>


Related articles: