JavaScript Tips
XML Menu Builder
Build powerful, client-side DHTML menus using XML for data and CSS for style. No JavaScript data! No having to place list elements on every single page of your website! No plug-ins!

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>