473,669 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

iframe and javascript

3 New Member
Hi! i have a html page with a iframe. I want to be able to select some text from iframe and when i push a button outside the iframe the selected tet shoul be copied in a text field ( the text field is also outside the iframe). I searh for days how to cummunicate between the iframe and parrent - and nothing. I already have a function in javascript wich copies the selected text in a text field (the text field is outside the iframes).

This is the code....
....
[HTML]<p>Some text outside the iframe.</p>
<iframe name="iframe1" id="iframe1" src="http://www.devittwiner y.com/our_wines.html" ></iframe>
<form>
<input type="text" name="textbox1" value="" />
<input onclick="copyit (this.form.text box1)" type="button" value="Copy" name="btnCopy" />
</form>
[/HTML]....

and the javascript function is:
Expand|Select|Wrap|Line Numbers
  1. function copyit(theField) {
  2. var selectedText = document.selection;
  3. if (selectedText.type == 'Text') {
  4. var newRange = selectedText.createRange();
  5. theField.focus();
  6. theField.value = newRange.text;
  7. } else {
  8. alert('select a text in the page and then press this button');
  9. }
  10. }
this is the function that works for a text outside the iframeeas. when i want to copy the text from the iframe instead of "var selectedText = document.select ion;" i put:

Expand|Select|Wrap|Line Numbers
  1. iframe = document.getElementById("iframe1");
  2. var selectText =iframe.contentWindow.selection;
  3.  
and i get a big error...

Can anyoane help me?... pls Thanks
Nov 15 '08 #1
5 2267
acoder
16,027 Recognized Expert Moderator MVP
Either use:
Expand|Select|Wrap|Line Numbers
  1. window.frames["iframe1"].document...
or where supported, contentDocument :
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("iframe1").contentDocument
or contentWindow.d ocument if not supported. You could also move the function into the iframe page and call it instead.

Note that the iframe page must be from the same domain.
Nov 15 '08 #2
iuniamadalina
3 New Member
Thank for your help. It realy helped me.

this is the code that works fine in firefox and with the iframe pages from my domain:

[HTML]<html>
<script>

function Settext()
{

var selectedText=do cument.getEleme ntById('ifrmChi ld').contentWin dow.getSelectio n();
document.all("t xtIndex").value = selectedText;

}
</script>
<body>


<input type="text" value="aaa" id="txtIndex"/>
<input type="button" onClick="Settex t();" value="Add text"/>
<br/>
<iframe src="subindex.h tml" id="ifrmChild" >
</body>
</html>
[/HTML]



But I want the page from iframe to be from defrent domain.

Is there a solution for my probleme?
Thanks
Nov 18 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
For a cross-browser selection code snippet, see this article.

For cross-domain iframe pages, you will need to serve the pages from your domain.
Nov 18 '08 #4
iuniamadalina
3 New Member
That article realy helped. Thank you so much
Nov 18 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
You're welcome :)
Nov 18 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
35558
by: Mel | last post by:
i need to have 2 side by side iframes, a link on top of the one will show/hide the other can someone help me pleeeeezzzzz ?
4
28000
by: christine.nguyen | last post by:
Hello, Here's the deal. I have an html page that contains an iframe. This iframe has an id that is unknown to me. This iframe also has test.html as it's source. Within test.html runs some javascript. Within this javascript that runs in test.html, I want to obtain the id of the iframe that loaded test.html in the first place. Is this possible?? I have no control over the iframe at all. The iframe will be loaded on some random html...
3
9558
by: Timo | last post by:
In javascript code on MyPage.aspx, I set a hidden IFRAME's source url: myframe.location.href = 'someotherpage.aspx'; If the session has timed out, preventing someotherpage.aspx from being loaded into the IFRAME, where can that error condition be trapped? Thanks Timo
13
6687
by: ukrbend | last post by:
I'm new to Javascript and to html and am trying to make the following code snippet work but it doesn't. It refuses to call the getPage() function and I always get a 404 error. I know the code is getting as far as the iframe section as other parts of the html code work correctly. But it is not executing any code within the getPage() function as some "hello world" writes within getPage() wouldn't print. ...
6
9378
by: paul | last post by:
HI! How do we send a variable from an Iframe page back to its parent? I have a script that calculates the iframe's window size but I need to know how to send that value back to its parent so I can use it there. Thanks in advance :) Paul
7
4724
by: ukrbend | last post by:
I use an iframe on my home page and everything works perfectly. But now I decided to add a popups to my page. The popups come not from within the iframe but from the parent frame. Again, everything regarding the popup works perfectly, it pops up with the correct data. But the strange thing is now any link that targets the iframe simply get ignored and instead of displaying things in the iframe they get displayed in a new browser window...
18
43541
by: Chris Ianson | last post by:
Hi geniuses (or is that genii, or genies) The challenge is as above really. I have a page with an iframe in it, and need to call a JS function in the *parent* page, *from* inside the iframe. (It's for Google Maps, but I won't bore you with the complexities of that, as it doesn't affect the question). Mochas kudos to anyone able to solve this widdle.
3
4480
by: PCgeek | last post by:
sorry moved this over to javascript forum, didn't mean to post 2x! Hi guys, I'm trying to put the finishing touches on my website and could really use some help on this particular issue. My page includes background music with a javascript music player on the main page below an iframe that is used for all content and navigation of the site and so that the music doesn't reload each time a page is switched. There is another javascript to resize...
5
7701
by: brad | last post by:
I'll post my code below. My goal is to grab the selected text in an iFrame from javascript (really any way possible). When I highlight text in the iFrame and click the link outside of the iFrame, I receive the following error: Firefox FireBug Error uncaught exception: Permission denied to get property HTMLDocument.getSelection IE7 Error
1
4887
by: cdmsenthil | last post by:
I have an Infragistics UltrawebGrid . Each Row in the grid is attached to a context menu using Infragistics CSOM Upon click on the menu, I am creating an Iframe dynamically which points to another page in the same domain which also contains infragistics datagid populated with default data retrieved from Data Base. After creating the frame I am attaching it to the HTML DOM and show it as modal popup with OK and Cancel Button inside an...
0
8465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8383
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8809
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2797
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.