Note that there are some explanatory texts on larger screens.

plurals
  1. POCopy to Clipboard for all Browsers using javascript
    primarykey
    data
    text
    <p>I was trying to make <strong>"Copy to Clipboard"</strong> work on all browsers but no luck.</p> <p>Am using javascript and I don't want to use <a href="http://zeroclipboard.org/" rel="noreferrer">Zero Clipboard</a> to do.</p> <p>Please let us know what wrong in my code.</p> <p>Appreciate for your help.</p> <p>Below is the code (Currently my code is working only on IE browser):- </p> <pre><code>&lt;script type="text/javascript"&gt; function copyToClipboard(s) { if( window.clipboardData &amp;&amp; clipboardData.setData ) { clipboardData.setData("Text", s); } else { // You have to sign the code to enable this or allow the action in about:config by changing user_pref("signed.applets.codebase_principal_support", true); netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard); if (!clip) return; // create a transferable var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable); if (!trans) return; // specify the data we wish to handle. Plaintext in this case. trans.addDataFlavor('text/unicode'); // To get the data from the transferable we need two new objects 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); } } &lt;/script&gt; &lt;textarea id='testText' rows="10" cols="100"&gt;Enter your Sample text&lt;/textarea&gt;&lt;br /&gt; &lt;button onclick="copyToClipboard(document.getElementById('testText').value);" &gt;clipboard&lt;/button&gt;&lt;br /&gt;&lt;br /&gt; &lt;textarea rows="10" cols="100"&gt;Paste your text here&lt;/textarea&gt;&lt;br /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload