Nov 21, 2009

Copy To Clipboard Function

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > JavaScript

Copy To Clipboard Function

pbolduc
I know how to code to get the text in a text area highlighted, I was wondering if anyone could provide me with the code to copy the content of a text area directly to the clipboard.

Thanks in advance,

Pete

Comment/Reply (w/o sign-up)

TavoxPeru
A time ago i need a script to do this action, and after some searching i found how to do it. You say that you have the code that selects the content text of the textarea, so, simply add a button to your form which will perform the action of copying it to the clipboard when it is clicked and the following javascript function, you can place this function in an external javascript file or in the HEAD section of your page.

Here is the Javascript code:
CODE
function copy(text) {
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text);
  }
}

And the button:
CODE
<input type="button" value="Copy To Clipboard" onclick="copy(document.your_form_name.your_textarea_name.value);">

I'm not pretty sure but i guess that it only works with Internet Explorer 6, i don't test it with any other browser.

Check also this topic One Click To Copy Script, Works in IE6 but not any other Browsers

Best regards,

 

 

 


Comment/Reply (w/o sign-up)

pbolduc
Thanks man...

sry I didn't thank you sooner but was on vacation

pete

Comment/Reply (w/o sign-up)

takashiro
QUOTE(TavoxPeru @ Dec 9 2007, 03:05 AM) *
A time ago i need a script to do this action, and after some searching i found how to do it. You say that you have the code that
.....

Thanks!! I am just finding it! Javascript copy function! I wonder if it will notice user to press "OK"?

Comment/Reply (w/o sign-up)

TavoxPeru
QUOTE(pbolduc @ Dec 19 2007, 03:13 PM) *
Thanks man...

sry I didn't thank you sooner but was on vacation

pete

You are welcome, do you test it in Firefox????

Best regards,

Comment/Reply (w/o sign-up)

TavoxPeru
QUOTE(takashiro @ Dec 20 2007, 05:34 AM) *
Thanks!! I am just finding it! Javascript copy function! I wonder if it will notice user to press "OK"?

You are welcome, and the function will not notice the user to press "OK" or any other key.

Best regards,

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)


See Also,

*SIMILAR VIDEOS*
Searching Video's for copy, clipboard, function
advertisement



Copy To Clipboard Function

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com