简体   繁体   English

使用JavaScript复制和粘贴剪贴板。或jQuery

[英]Copy and paste clipboard in JavaScript. or jQuery

如何复制div标签中的内容并将其粘贴到Paint,Powerpoint等应用程序中。

It is not easy but possible: 这不容易但可能:

function copyToClipboard(meintext) {  
if (window.clipboardData)   
     window.clipboardData.setData("Text", meintext);  
else if (window.netscape) {  
     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');  
     var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);  
     if (!clip)  
          return false;  
     var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);  
     if (!trans)  
          return false;  
     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);  
     str.data=meintext;  
     trans.setTransferData("text/unicode",str,meintext.length*2);  
     var clipid=Components.interfaces.nsIClipboard;  
     if (!clipid)  
          return false;  
     clip.setData(trans,null,clipid.kGlobalClipboard);  
}  
     return false;  
}

Please note. 请注意。 The first two lines are for IE. 前两行是针对IE的。

All the following for Firefox. 以下是Firefox的所有内容。 And for Firefox the clipboard has to be enabled: 对于Firefox,必须启用剪贴板:

Open about:config set signed.applets.codebase_principal_support to true . 打开about:config set signed.applets.codebase_principal_supporttrue

Or just use some Flash-stuff :) 或者只是使用一些Flash东西:)

你可以使用jquery剪贴板 ,在这里查看主页

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jquery/javascript 复制到剪贴板 - Jquery/javascript copy to clipboard 如何在 JavaScript 中复制到剪贴板。 在 data-value 中包含值 - How to copy to the clipboard in JavaScript. Including the value in the data-value 使用JavaScript将所选文本复制并粘贴到剪贴板 - Copy and paste the selected text to the clipboard using JavaScript 使用javascript在剪贴板中复制/粘贴内容 - Copy / Paste content to and from clipboard using javascript 使用jquery或javascript将文本复制到剪贴板 - copy text to clipboard with jquery or javascript 在JavaScript或jQuery中是否有“复制到剪贴板”功能? - Is there a “copy to clipboard” function in JavaScript or jQuery? 使用JavaScript / jquery复制url并粘贴到台式机,ios和android上的剪贴板按钮上 - copy url and paste to clipboard button on desktop, ios and android using JavaScript/jquery 将超链接文本和纯文本复制到剪贴板,然后在一行的多个单元格中使用 Javascript/JQuery 将它们粘贴到 Excel? - Copy hyperlink text and plain text to the clipboard, then paste them into Excel using Javascript/JQuery in multiple cells of a row? 剪切副本粘贴jQuery / Javascript - Cut Copy Paste jQuery/Javascript javascript剪切/复制/粘贴到剪贴板:谷歌是如何解决它的? - javascript cut/copy/paste to clipboard: how did Google solve it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM