Ultra fast cheap  linux and windows hosting
javascript tutorial Browse Basic JavaScript Tutorial
Browse JavaScript Script resources
Browse javascript FAQS
Categories:

javascript tutorial
buy template
Home >> Tutorials >> Advanced javascript tutorials

Copy text To Clipboard

This example will copy text on the page to the clipboard (then try using the menu to paste...)



<html>
<head>
<script>
function CopyToClipboard()
{
  obj = null;
  if(document.getElementById)
    obj=document.getElementById('the_code');

  if (obj) { window.clipboardData.setData('Text', obj.innerText); }
}
</script>
</head>

<body>

<script>
if(document.getElementById)
  document.write(" <a href='javascript:CopyToClipboard()'>Copy Example Code to your Clipboard</a>");
</script>

<table border=1>
<tr><td><span id='the_code'> 

This example will 
copy text in the table to the clipboard (then try using the menu to paste...) 
</span></td></tr></table></body>
</html>

 

 

 

 

 

 

 

 

 

 

 

 

 

Explanation of code:

(1) When you click on the link Copy Example Code to your Clipboard function CopyToClipboard() will be called. In this function getElementById() method returns the first occurrence of the ID attribute value, the_code.

(2) Then setData method of clipboardData object assigns data in a specified format to the clipboardData object .


Page contents: itechies.net - Copy text To Clipboard
javascript tutorial
javascript book
Buy this book