frequently ask ? : Computers : Programming : Languages : JavaScript : Document

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

21 of 26 people (81%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I allow the user to select the page content and copy it to the clipboard?

Mar 16th, 2001 07:59
Martin Honnen,


IE4+ allows that:
<HTML>
<HEAD>
<TITLE>
copying page content to the clipboard
</TITLE>
</HEAD>
<BODY>
<INPUT TYPE="button" VALUE="copy page content to clipboard"
       ONCLICK="if (document.body && document.body.createTextRange()) {
                  var range = document.body.createTextRange();
                  range.select();
                  document.execCommand('Copy');
                  document.selection.empty();
                }"
>
<P>
All for Kibology.
</P>
<DIV>
Kibology for all.
</DIV>
<A HREF="http://JavaScript.FAQTs.com">
JavaScript.FAQTs.com
</A>
</BODY>
</HTML>
Though it should in my view be easier for the user to simply use Select 
All->Copy from the edit or context menu.