Click here to Skip to main content
15,910,277 members
Please Sign up or sign in to vote.
1.00/5 (1 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 "http://www.w3schools.com/html/tryit.asp?filename=tryhtml_frame_mix". The copy to clipboard optionis for the articles displayed in the main menu.
The code is:
HTML
<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>
</SPAN> 
<TEXTAREA ID="holdtext" STYLE="display:none;">
</TEXTAREA>
 <BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON>


JavaScript
<SCRIPT LANGUAGE="JavaScript">
 
function ClipBoard() 
{
 holdtext.innerText = copytext.innerText;
 Copied = holdtext.createTextRange();
 Copied.execCommand("RemoveFormat");
 Copied.execCommand("Copy");
 }
 
</SCRIPT>


For iframe i am using this :
HTML
<iframe src="text.txt" frameborder="0" scrolling="yes" height="400" width="650">
  Text file not found.
 </iframe>
Posted
Updated 16-Dec-11 6:38am
v4
Comments
Sergey Alexandrovich Kryukov 16-Dec-11 13:22pm    
Better! Then please see my other answer.
--SA

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.

—SA
 
Share this answer
 
v4
Comments
Sergey Alexandrovich Kryukov 16-Dec-11 13:12pm    
OP commented:

@ SAKryukov: i have updated the question now. thanks
Sergey Alexandrovich Kryukov 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.
--SA
In response to clarified question:

For this purpose, I would use jQuery library which you can freely download from http://docs.jquery.com/Downloading_jQuery[^].

This is a jQuery plug-in good to copy any data to the client's clipboard: http://archive.plugins.jquery.com/project/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,
—SA
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900