Copy and paste clipboard in JavaScript. or jQuery

It is not easy but possible:

function copyToClipboard(meintext) {  
if (window.clipboardData)   
     window.clipboardData.setData("Text", meintext);  
else if (window.netscape) {'UniversalXPConnect');  
     var clip = Components.classes[';1'].createInstance(Components.interfaces.nsIClipboard);  
     if (!clip)  
          return false;  
     var trans = Components.classes[';1'].createInstance(Components.interfaces.nsITransferable);  
     if (!trans)  
          return false;  
     var str = new Object();  
     var len = new Object();  
     var str = Components.classes[";1"].createInstance(Components.interfaces.nsISupportsString);;  
     var clipid=Components.interfaces.nsIClipboard;  
     if (!clipid)  
          return false;  
     return false;  

Please note. The first two lines are for IE.

All the following for Firefox.
And for Firefox the clipboard has to be enabled:

Open about:config
set signed.applets.codebase_principal_support to true.

Or just use some Flash-stuff 🙂

Leave a Comment