Click here to Skip to main content
Rate this: bad
good
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 "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:
<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>
 
<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 :
<iframe src="text.txt" frameborder="0" scrolling="yes" height="400" width="650">
  Text file not found.
 </iframe>
Posted 15-Dec-11 12:03pm
Edited 16-Dec-11 7:38am
v4
Comments
SAKryukov at 16-Dec-11 13:22pm
   
Better! Then please see my other answer.
--SA
Rate this: bad
good
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.
 
—SA
  Permalink  
v4
Comments
SAKryukov at 16-Dec-11 13:12pm
   
OP commented:
 
@ SAKryukov: i have updated the question now. thanks
SAKryukov at 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
Rate this: bad
good
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 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
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 105
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 16 Dec 2011
Copyright © CodeProject, 1999-2014
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