Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Copy To Clipboard Function
pbolduc
post Dec 8 2007, 09:54 PM
Post #1


Member - Active Contributor
Group Icon

Group: Members
Posts: 92
Joined: 15-December 04
From: New Mexico
Member No.: 1,759



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
Go to the top of the page
 
+Quote Post
TavoxPeru
post Dec 9 2007, 03:05 AM
Post #2


Super Member
Group Icon

Group: [HOSTED]
Posts: 745
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



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,

This post has been edited by TavoxPeru: Dec 9 2007, 03:43 AM
Go to the top of the page
 
+Quote Post
pbolduc
post Dec 19 2007, 08:13 PM
Post #3


Member - Active Contributor
Group Icon

Group: Members
Posts: 92
Joined: 15-December 04
From: New Mexico
Member No.: 1,759



Thanks man...

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

pete
Go to the top of the page
 
+Quote Post
takashiro
post Dec 20 2007, 10:34 AM
Post #4


Member [ Level 1 ]
Group Icon

Group: [HOSTED]
Posts: 44
Joined: 26-August 07
Member No.: 24,372



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"?
Go to the top of the page
 
+Quote Post
TavoxPeru
post Dec 20 2007, 12:00 PM
Post #5


Super Member
Group Icon

Group: [HOSTED]
Posts: 745
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



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,
Go to the top of the page
 
+Quote Post
TavoxPeru
post Dec 20 2007, 12:02 PM
Post #6


Super Member
Group Icon

Group: [HOSTED]
Posts: 745
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



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,
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics


 



- Lo-Fi Version Time is now: 5th September 2008 - 09:01 AM