473,606 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accesing an IFrame from an internal element

I have an html page with an iframe on it. Inside the iframe there is an img
element. I am looking how to reference the iframe from the img element
contained on it and cannot find a way to do it. I am using FireFox 1.5.0.1

I am looking for something like myImg.container .

Can someone help me ?

Thanks in advance
*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
Feb 22 '06 #1
13 4125
d
"Fernando Deutsch" <fd************ @nospambitam.co m> wrote in message
news:43******** *************** @titian.nntpser ver.com...
I have an html page with an iframe on it. Inside the iframe there is an img
element. I am looking how to reference the iframe from the img element
contained on it and cannot find a way to do it. I am using FireFox 1.5.0.1

I am looking for something like myImg.container .

Can someone help me ?
window, isn't it?
Thanks in advance
*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from
http://www.SecureIX.com ***

Feb 22 '06 #2
Fernando Deutsch wrote on 22 feb 2006 in comp.lang.javas cript:
I have an html page with an iframe on it. Inside the iframe there is
an img element. I am looking how to reference the iframe from the img
element contained on it and cannot find a way to do it.
window

[To the image the page of the iframe is just that,
perhaps I read your Q wrong, however]
I am using FireFox 1.5.0.1


Are you only building for yourself?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 22 '06 #3
No, window returns undefined.

I have tried so far

element.window;
element.ownerDo cument.window;

where element is the img object and both expressions returns undefined.
Are you only building for yourself?
I did not understand what you mean.

Thanks anyway

"Evertjan." <ex************ **@interxnl.net > wrote in message
news:Xn******** ************@19 4.109.133.242.. . Fernando Deutsch wrote on 22 feb 2006 in comp.lang.javas cript:
I have an html page with an iframe on it. Inside the iframe there is
an img element. I am looking how to reference the iframe from the img
element contained on it and cannot find a way to do it.


window

[To the image the page of the iframe is just that,
perhaps I read your Q wrong, however]
I am using FireFox 1.5.0.1


Are you only building for yourself?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
Feb 22 '06 #4
No, window returns undefined.

I have tried so far

element.window;
element.ownerDo cument.window;

where element is the img object and both expressions returns undefined.

Thanks anyway

"d" <d@example.co m> wrote in message
news:zK******** **********@text .news.blueyonde r.co.uk...
"Fernando Deutsch" <fd************ @nospambitam.co m> wrote in message
news:43******** *************** @titian.nntpser ver.com...
I have an html page with an iframe on it. Inside the iframe there is an img element. I am looking how to reference the iframe from the img element
contained on it and cannot find a way to do it. I am using FireFox 1.5.0.1
I am looking for something like myImg.container .

Can someone help me ?


window, isn't it?
Thanks in advance
*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from
http://www.SecureIX.com ***


*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
Feb 22 '06 #5
Fernando Deutsch wrote:
I have tried so far

element.window;
element.ownerDo cument.window;


This looks quite strange, he asked you to use the window global variable.

alert(window);

If you're "inside" the iframe, this will be a reference to it.
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Feb 22 '06 #6
Fernando Deutsch wrote on 22 feb 2006 in comp.lang.javas cript:
"Evertjan." <ex************ **@interxnl.net > wrote in message
news:Xn******** ************@19 4.109.133.242.. .
Fernando Deutsch wrote on 22 feb 2006 in comp.lang.javas cript:
> I have an html page with an iframe on it. Inside the iframe there
> is an img element. I am looking how to reference the iframe from
> the img element contained on it and cannot find a way to do it.
window

[To the image the page of the iframe is just that,
perhaps I read your Q wrong, however]
[please do not toppost on usenet]
No, window returns undefined.
Imposssible, as windows is the top-of-DOM.
I have tried so far

element.window;
element.ownerDo cument.window;
where element is the img object and both expressions returns
undefined.


This is nonsense code, you cannot go above the window in a page.
Windows does not have to derive from your img object, as you are on theat
page with your javascript, acording to your Q.

Try:
alert(windows.d ocument.body.st yle.color)

Reread your Q and see that the answer to your Q is sound,
then refrase your question to what you realy wanted to know.

=============== ============

You left out this quote:
">>> I am using FireFox 1.5.0.1 "
Are you only building for yourself?


I did not understand what you mean.


It does not matter if you are using FF or IE,
it matters what your users use.
Or is the page build for your personal use only?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 22 '06 #7
May look as nonsense code to you, because you dont know the whole context of
the application.

Basically I have a html page with the iframe that contains an img element.
On that page (not inside the iframe) I have a collection that contains a
reference to the img object of the iframe.

So I am looking to see what object would be the "window container" of that
img . As I have a reference to the img object I can navigate to its owner
document, and from it, I should be able to reach its window (expecting the
iframe) but I got an undefined object.

According to the Mozilla Document Interface
http://www.mozilla.org/docs/dom/domr...ef.html#998664 I should be
able to get the window by the property contentWindow.

About the browser, I have resolved the situation for IE, I am looking for a
solution on FF.

This is nonsense code, you cannot go above the window in a page.
Windows does not have to derive from your img object, as you are on theat
page with your javascript, acording to your Q.

Try:
alert(windows.d ocument.body.st yle.color)

Reread your Q and see that the answer to your Q is sound,
then refrase your question to what you realy wanted to know.

=============== ============

You left out this quote:
">>> I am using FireFox 1.5.0.1 "
Are you only building for yourself?


I did not understand what you mean.


It does not matter if you are using FF or IE,
it matters what your users use.
Or is the page build for your personal use only?

*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
Feb 22 '06 #8
"Fernando Deutsch" <fd************ @nospambitam.co m> writes:

Please don't top post!
May look as nonsense code to you, because you dont know the whole context of
the application.
More likely because he knows how the DOM works.

You wrote, e.g.:
element.window
and
element.ownerDo cument.window

That's just blind guessing on your part, and it works as well as
could be expected from that. The element does have an "ownerDocum ent"
property (as specified by W3C DOM Core), but neither the document
nor the element has a reference to a window object.
So I am looking to see what object would be the "window container" of that
img . As I have a reference to the img object I can navigate to its owner
document, and from it, I should be able to reach its window (expecting the
iframe) but I got an undefined object.
The error is your assumption that you can go from a DOM element to
the window containing the DOM document of the element. The window object
is not a DOM object, so the DOM specification doesn't say how to find
it.

You might be able to use document.defaul tView, as some browsers have
that property point to the window object. It is not specified that the
defaultView should also be the global object, or a window object, and
it's not available in all browsers, so it's not a good solution.
According to the Mozilla Document Interface
http://www.mozilla.org/docs/dom/domr...ef.html#998664 I should be
able to get the window by the property contentWindow.


That's a property on the DOM element of the iframe in the parent document,
not on an element in the window you want to find.

You could also just do (in the parent window):
frames["iframeId"]
to get the window object of the embedded iframe with id="iframeId".

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Feb 23 '06 #9
Lasse Reichstein Nielsen wrote:
The error is your assumption that you can go from a DOM element to
the window containing the DOM document of the element. The window object
is not a DOM object, so the DOM specification doesn't say how to find
it.
Rather unfortunate, that.
You might be able to use document.defaul tView, as some browsers have
that property point to the window object. It is not specified that the
defaultView should also be the global object, or a window object, and
it's not available in all browsers, so it's not a good solution.


Thanks for the tip, I had missed it before. I just tested it out on my
Firefox 1.5 / Win XP Pro and it is working fine. Here is what I did:
Main page:
<html><head><ti tle>Containing Page</title>
<script type='text/javascript'>
function onLoad() {
var iframe = document.getEle mentById('myfra me');
var elemInFrame = iframe.contentD ocument.getElem entById('myElem ');
var elemWindow = elemInFrame.own erDocument.defa ultView;
elemWindow.setT imeout ("document.getE lementById('mys pan').innerHTML =
\
'The answer is: mozilla'", 100);
}
</script>
</head><body onload="onLoad( )">
This page contains a single iframe with
an image element to see if we can get to
that element's containing window<br><br>
<iframe id=myframe src="frame.htm"
style="height:4 in;width:6in"></iframe>
</body></html>
Frame.htm:
<html><head><ti tle>Frame Page</title></head>
<body>
This is the frame<br><br>
<span id=myspan style="border:1 px solid green">
This text in the frame should get replaced</span><br><br>
<div>
<img id=myElem src="https://www.mozilla.org/images/header_logo.gif ">
</div>
</body></html>
The above test also works for IE 6, if I change the middle two lines of
script to:
var elemInFrame = iframe.Document .getElementById ('myElem');
var elemWindow = elemInFrame.doc ument.parentWin dow;
Csaba Gabor from Vienna

Feb 23 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
24612
by: Martin | last post by:
There seems to be some strange behaviour when trying to get the scrollHeight and scrollTop of an iframe in IE6. I have tried several ways of getting these values when the iframe is written into the html. The following return the correct values in IE6, where the iframe's id is 'f': f.document.body.scrollHeight f.document.body.scrollTop window.frames.document.body.scrollHeight
3
14430
by: Ryh | last post by:
I have the following scritpt. It hides div layer when mouse is out of the div layer. Inside DIV I have IFRAME box. Unfortuantely it does not work in Mozilla or IE 5.5. It hides div when cursor is inside IFRAME. NOte that IFRAME is inside DIV so it should not hide DIV. It Works fine in IE6.0. Could any one help? Example:
5
35556
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 ?
7
4841
by: Christopher J. Hahn | last post by:
I'm trying to use a script-generated form to submit to a script-generated iframe. The problem I'm running into is that the iframe is not assuming the name I assign it. IE6 on Win2000. FF1.0.2+ doesn't seem to have the problem. I'm doing: this.iframe = document.createElement( 'iframe' ); this.iframe.id = this.id + 'wh'; this.iframe.style.display = 'none';
5
1121
by: Michael | last post by:
Hi I have a ASP.NET with an IFrame element that contains a another page. When this internal page loads I want the IFrame to increase in height so that all of the contents can be displayed. I've tried a number of ways, but none seem to work as they always miss the bottom 100 or so pixels. Is there any way to find the total height of the internal IFrame document? Can I get the IFrame to automatically resize itself? Any help would be very...
1
7234
by: Testing12340 | last post by:
Hello!, I have this well, little IE issue. I'm showing hiding div's (containing IFRAMES), however, for some reason in IE one of the iframe contents allow me to click them (the last one allows me to browse the contents) the others I can't do anything with :(, it's like there is still a layer present (invisible) It works fine in FF If someone knows the answer, THANKS!
1
8123
by: Z1P2 | last post by:
I would like to gradually resize an iframe in an onmouseover event. I can easily do it with an image, but when I try to do it with an iframe, it doesn't do anything. So first of all, is it possible to gradually zoom an iframe, and if so, what am I missing? Here is the script I am trying to manipulate, between the head tags: <script language=JavaScript> /**** adjust these two parameters to control how fast or slow
1
3141
by: John L. | last post by:
How do I invoke the scroll() method of a window object for a scrollable IFRAME element in an HTML document? I am using IE 7.0, and I thought the following would work: document.frame01.scroll(x,y) or possibly document.getElementById('frame01').scroll(x,y)
0
8432
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8078
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8299
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...
1
5962
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5456
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
3919
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
3964
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1548
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.