JavaScript Tips

Buy this website for $5000 USD

Priced to sell, this is an established JavaScript website, growing in popularity as evidenced by its Alex ranking. Includes most website content. The price is NON-NEGOTIABLE. Serious buyers should contact

Sending Text to the Clipboard with Internet Explorer

Internet Explorer for Windows has a proprietary clipboard object called clipboardData that enables you to perform web page clipboard operations with JavaScript.

Above is a button that, when pressed, sends the text "Top of the world, Ma" to the clipboard. It will only work in Internet Explorer, yet will not cause errors in other browsers, if tried. Here is the source code:

<script type="text/javascript">
   function sendToClipboard(s)
   {
      if( window.clipboardData && clipboardData.setData )
      {
         clipboardData.setData("Text", s);
      }
      else
      {
         alert("Internet Explorer required");
      }
   }
</script>

<button onclick="sendToClipboard('Top of the world, Ma')">
Send text to clipboard</button>