Cross-browser Javascript copy button
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/400212/how-to-copy-to-the-clipboard-in-javascript">How to copy to the clipboard in JavaScript?</a>  </p>
</blockquote>



<p>I am trying to implement a cross-browser Javascript copy button, but am unable to use Flash, unfortunately, so I've come up with a different solution for Chrome/Firefox, etc.</p>

<p>The issue I'm having is the syntax for actually calling the function: it seems that IE doesn't like if I have an apostrophe in the argument, and nothing else likes it if I <em>don't</em>. For example, the HTML:</p>

<pre><code>&lt;button onclick="copy(el)"/&gt;Copy&lt;/button&gt;
</code></pre>

<p>Works fine with the IE-only Javascript:</p>

<pre><code>textRange = document.body.createTextRange();
textRange.moveToElementText(el);
textRange.execCommand("Copy");
</code></pre>

<p>But when I try to do the following for Chrome/Firefox, I get a Type Mismatch error in Firebug:</p>

<pre><code>document.getElementById(el).innerHTML;
</code></pre>

<p>If I add apostrophes around the argument in the original function call (onclick="copy('el')"), it works fine in Chrome/Firefox, but IE gives a type mismatch error.</p>

<p>How can I resolve this so that I can call the function&mdash;preferably with apostrophes around the arguement&mdash;but it will work in all browsers? Thanks.</p>
