Monday, April 18, 2011

Copy on Clipboard using Javascript

I needed to have functionality of copying contents of textbox on clipboard at my aspx page. This is how I implement it

Objects:

Width="596px">


Script:
function CopyToClipboard()
{
var textboxVal = document.getElementById("txtScript").value; //txtText id of a textbox
if( window.clipboardData && clipboardData.setData )
{
clipboardData.setData("Text", textboxVal);
}
else
{
//alert("You should upgrade you browser,works only in IE4+");
}
}