zoukankan      html  css  js  c++  java
  • JS复制文本到剪切板

    View Code
     1 function copyToClipboard(txt) {  
     2      if(window.clipboardData) {  
     3        window.clipboardData.clearData();  
     4        window.clipboardData.setData("Text", txt);  
     5        alert("Your request has been processed successfully.");  
     6      } else if(navigator.userAgent.indexOf("Opera") != -1) {  
     7       window.location = txt;  
     8      } else if (window.netscape) {  
     9       try {  
    10        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
    11       } catch (e) {  
    12        alert("被浏览器拒绝!\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");  
    13       }  
    14       var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);  
    15       if (!clip)  
    16        return;  
    17       var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);  
    18       if (!trans)  
    19        return;  
    20       trans.addDataFlavor('text/unicode');  
    21       var str = new Object();  
    22       var len = new Object();  
    23       var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);  
    24       var copytext = txt;  
    25       str.data = copytext;  
    26       trans.setTransferData("text/unicode",str,copytext.length*2);  
    27       var clipid = Components.interfaces.nsIClipboard;  
    28       if (!clip)  
    29        return false;  
    30       clip.setData(trans,null,clipid.kGlobalClipboard);  
    31       alert("Your request has been processed successfully.");  
    32      }  
    33     } 
  • 相关阅读:
    《linux 必读》
    ldd ldconfig
    rpm 数据库
    /bin, /sbin & /usr/bin, /usr/sbin & /usr/local/bin, /usr/local/sbin & glibc
    POSIX
    CentOS 下载地址
    insert into TABLE by SELECT ...
    httpd 处理模型
    http 状态码
    IP地址 0.0.0.0 是什么意思?
  • 原文地址:https://www.cnblogs.com/whlhaikuotiankong/p/2719335.html
Copyright © 2011-2022 走看看