Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
38
rated 0 times [  42] [ 4]  / answers: 1 / hits: 73321  / 13 Years ago, sat, august 27, 2011, 12:00:00

Possible Duplicate:

Copy selected text to the clipboard WITHOUT using flash - must be cross-browser






This one has kept me going for a long time. How would I copy text to the clipboard? Here is my code:



<body>
<textarea name=text rows=5 cols=20 wrap=hard onblur=CopyToClipboard()>Enter text here and it will be copied to the clipboard!</textarea>
</body>

<script type=text/javascript>
function CopyToClipboard() {
//O_O Confused... what do I do...
}
</script>

More From » clipboard

 Answers
31

Here is one way you can do it...



<body>
<textarea rows=5 cols=20 wrap=hard onblur=CopyToClipboard(this)></textarea>
</body>

<script language=JavaScript>
function CopyToClipboard(text) {
Copied = text.createTextRange();
Copied.execCommand(Copy);
}
</script>


This only works with IE 4 and above. When you run it, a dialog may come up asking you whether or not you want this website to have access to your clipboard. Click yes if it does. Whatever text the user entered into the box will be copied to the clipboard.


[#90383] Thursday, August 25, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleew

Total Points: 70
Total Questions: 87
Total Answers: 117

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
;