Click here to Skip to main content
13,048,406 members (147,816 online)
Rate this:
Please Sign up or sign in to vote.
Hi All,

I was wondering if copy to clipboard is available for iframe. i tried to search on google and no joy. Could somebody please advise?
Thanks in advance.

Ok So I am having a website and there was already a copy to clipboard option for which i used Javascript code and that worked perfectly fine but now i have iframe and the copy to clipboard function does not work anymore. I have a html website. I have a web based page(html- frames format) for our text documents articles on various subjects. The page is made in three frames. It's exactly like this "". The copy to clipboard optionis for the articles displayed in the main menu.
The code is:
<SPAN ID="copytext" STYLE="height:;width:;background-color:">
<p>Please do the following:<br />
                    1. Click on Edit > Preferences<br />
                    2. Select the Multimedia Trust (legacy) Category on left side of window<br />
                    3. Select 'Other Documents' under 'Trust Options' frame<br />
                    4. Select 'Permission for Adobe(R) Flash(R) Player is set to Prompt' in<br />
                    list box<br />
                    5. Change value for Change permission for selected multimedia player<br />
                    to: 'Always'<br />
                    6. Click 'OK'                  </p>
                  <p>Kind Regards,</p>
<TEXTAREA ID="holdtext" STYLE="display:none;">
 <BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON>

function ClipBoard() 
 holdtext.innerText = copytext.innerText;
 Copied = holdtext.createTextRange();

For iframe i am using this :
<iframe src="text.txt" frameborder="0" scrolling="yes" height="400" width="650">
  Text file not found.
Posted 15-Dec-11 11:03am
Updated 16-Dec-11 6:38am
SAKryukov 16-Dec-11 13:22pm
Better! Then please see my other answer.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Anything on the Web page can be copied to the clipboard.

If you want to do it programmatically, 1) think twice if you really want it; normally, the users themselves can do it better; 2) if you are decisively want it and still have a problem, go back to your question, tag your technology, language and other relevant information and explain how exactly you want it, to what context, and what exactly the problem is; show us the code you tried; in this case, use "Improve question" above.

SAKryukov 16-Dec-11 13:12pm
OP commented:

@ SAKryukov: i have updated the question now. thanks
SAKryukov 16-Dec-11 13:13pm
First of all, please don't post anything as solution unless you really want to post a solution.
Add a comment via "Have a Question or Comment?", use "Improve question" or reply to an existing comment.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

In response to clarified question:

For this purpose, I would use jQuery library which you can freely download from[^].

This is a jQuery plug-in good to copy any data to the client's clipboard:[^].

Also, if you need to copy the content of you iframe, please understand that getting any element data statically won't help you, because the real content of the frame is places in a separate resource. You need to download it first, presumably via Ajax.

Please see my code samples where I demonstrated the jQuery techniques in my recent answer: using javascript retrieving value from iframe[^].

Remember that Ajax is asynchronous in its nature, and that's good for you as you don't really want to use any blocking calls in your JavaScript. Perform your clipboard operation in the callback, as it is shown in my first code sample.

Good luck,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 16 Dec 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100