Last post Jan 10, 2011 05:42 AM by Ashish Sharma
Nov 21, 2006 05:53 PM|KowDot|LINK
I have spent a huge amount of time searching for a script to copy the contents of a textarea to the clipboard. There are lots of examples about but none that I can get to work!
Please does anyone have something that works for both FF and IE? Thanks.
Nov 22, 2006 11:48 PM|Haissam|LINK
Check the below url so you can find the answer of your question
Nov 23, 2006 12:43 AM|KowDot|LINK
Desperately need a solution fast.
Nov 23, 2006 02:14 PM|Haissam|LINK
Dear try this
var copyText = document.getElementById('content').document.body.createTextRange().text;
Nov 23, 2006 06:00 PM|KowDot|LINK
var copyText = document.getElementById('holdtext').document.body.createTextRange().text;
<form id="form1" runat="server">
<textarea cols="10" rows="10" id="holdtext"></textarea>
Copy to Clipboard</button>
Can't get it to work! Just copies the id of the textarea, i.e. holdtext
Any help from anyone appreciated, thanks...
Nov 23, 2006 06:08 PM|haoest|LINK
To note, I think user has preference to set their browser to not allow manipulation of clipboard via script.
Nov 23, 2006 10:14 PM|KowDot|LINK
Good point haoest, maybe that's why I have been having so much trouble. Found this:
but still can't get it to work!
Nov 23, 2006 11:02 PM|haoest|LINK
Personally, I copy my password, creditcard number, or phone numbers occasionally when I fill out forms, if script can read the content, I woudln't be too comfortable. I suggest you leave out this feature, or at least not putting any extreme effort on it.
Can you share your problem from a bigger picture, like what you want to accomplish with clipboard? There maybe other solutions.
Nov 24, 2006 10:52 AM|KowDot|LINK
Thanks haoest. I'm basically providing to users the ability to have some of my website content on their sites - to do this they need to copy and paste some code that is displayed in a textarea.
I'm going to ditch the copy to clipboard idea and just force them to right click over the top and select copy!
Thanks for your help.
Nov 24, 2006 04:16 PM|Haissam|LINK
Nov 29, 2006 05:33 PM|KowDot|LINK
Thanks Haissam I'll have a look.
My solution is that when they click on the textarea it highlights the entire area. They simply right click to copy. Here's the code which has been tested for both IE7 and FF2:
var control = document.getElementById(ID);
var length = control.value.length;
var range = control.createTextRange();
else if (control.setSelectionRange)
<form id="form1" runat="server">
<textarea id="taCode" runat="server" cols="20" rows="10" readonly="readonly" style="overflow: scroll;
overflow-y: scroll; overflow-x: hidden; overflow: -moz-scrollbars-vertical;">This is the text that I want to be able to copy</textarea>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
taCode.Attributes.Add("onclick", "Select('" & GetClientID() & "');")
Public Function GetClientID() As String
If Not IsNothing(taCode) Then Return taCode.ClientID Else Return Nothing
Hope this helps someone...thanks everyone
Apr 20, 2010 02:41 PM|mnadeem|LINK
Dear friend, it is possible to access clipboard data in IE but it is impossible to access the clipboard data in Firefox for a webpage. You can change some privileged setting for Firefox but that will run only on the browser where setting is done.
For a webpage user can open it anywhere and you cant say the user to change the settings manually before accessing the page.
Please see this.
Jun 27, 2010 06:12 PM|Jose Fraga|LINK
mnadeem is right, anyway, you can use flash to afford this:
Jan 10, 2011 05:42 AM|Ashish Sharma|LINK
With JS you can copy the content of TextBox to Clipboard
var textboxVal = document.getElementById("