...

View Full Version : javascript Copy to clip board from text area



amskape
11-18-2011, 04:14 PM
Hi Friends,
I need a copy to clipboard functionality from a text area using javascript. I use Zclip for the purpose,
but it will not work as needed . I attach my working code along with this .. pls open index.html in browser
and try it . Do any one can pls give a javascript solution to copy textarea content to clipboard...

Thanks,
Anes :cool:

Philip M
11-18-2011, 05:13 PM
Try this:-


<textarea id="copytext1" rows = "12" cols = "24">
This text will be copied onto the clipboard when you click the button below.
</textarea>

<textarea id="holdtext" style ="display:none;"></textarea>
<br><br>
<input type = "button" onClick="ClipBoard();" value = "Copy to Clipboard"</button>

<script type = "text/javascript">

function ClipBoard() {
holdtext.innerText = copytext1.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("RemoveFormat");
Copied.execCommand("Copy");
window.status="Contents copied to clipboard"
setTimeout("window.status=''",2500);
}

</script>


"Jason McGuire takes a look between his legs and likes what he sees." - Football commentator

felgall
11-18-2011, 07:00 PM
If you are attempting that in any browser except Internet Explorer then it isn't going to work as IE is the only browser that provides such access to the clipboard.

Philip M
11-18-2011, 08:28 PM
If you are attempting that in any browser except Internet Explorer then it isn't going to work as IE is the only browser that provides such access to the clipboard.

A good reason for using IE! ;);)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum