IE and iframe

K

karthickdevi

Hi,

I am calling an iframe from my parent document. In the parent document,
i used the following script to get the value of the textfield present
in the iframe. This doesn't seem to work in IE.

Please advise.


window.frames['myframe'].document.getElementsByName('mytextfield')[0].value

Thanks for your help,
Dev.
 
J

Jonas Raoni

(e-mail address removed) escreveu:
I am calling an iframe from my parent document. In the parent document,
i used the following script to get the value of the textfield present
in the iframe. This doesn't seem to work in IE.

Please advise.

window.frames['myframe'].document.getElementsByName('mytextfield')[0].value

<iframe> doesn't behave like the <frame>, so you won't find your
<iframe> inside the "window.frames" collection.

Grab your <iframe> by using getElementById ^^
 
R

Richard Cornford

Jonas said:
(e-mail address removed) escreveu:
I am calling an iframe from my parent document. In the
parent document, i used the following script to get the
value of the textfield present in the iframe. This doesn't
seem to work in IE.

Please advise.

window.frames['myframe'].document.getElementsByName('mytextfield')
[0].value

<iframe> doesn't behave like the <frame>, so you won't find your
<iframe> inside the "window.frames" collection.

You can reference the window object contained in an IFRAME through the
global - frames - collection, by integer index and by NAME attribute
(but not by ID attribute) in IE.
Grab your <iframe> by using getElementById ^^

A reference to an IFRAME element is not the same as a reference to the
global/window object contained in the IFRAME.

Richard.
 
M

Martijn Saly

Hi,

I am calling an iframe from my parent document. In the parent document,
i used the following script to get the value of the textfield present
in the iframe. This doesn't seem to work in IE.

Please advise.


window.frames['myframe'].document.getElementsByName('mytextfield')[0].value

Thanks for your help,
Dev.

getElementsByName doesn't exist in any standard. So I wouldn't use that
if I were you.

Also note that if the iframe is served by another (sub)domain, it would
be considered cross-site scripting, which is almost always blocked.
 
R

Richard Cornford

Martijn said:
(e-mail address removed) wrote:
window.frames['myframe'].document.getElementsByName('mytextfield')[0].value
getElementsByName doesn't exist in any standard. So I wouldn't use that
if I were you.
<snip>

If the W3C HMTL DOM level 1 and 2 recommendations are not enough of a
standard for you what exactly does "exist in any standard"?

Richard.
 
M

Martijn Saly

Richard said:
Martijn said:
(e-mail address removed) wrote:
window.frames['myframe'].document.getElementsByName('mytextfield')[0].value
getElementsByName doesn't exist in any standard. So I wouldn't use that
if I were you.
<snip>

If the W3C HMTL DOM level 1 and 2 recommendations are not enough of a
standard for you what exactly does "exist in any standard"?

Richard.

Oops, I guess I overlooked that one. But in any case, on this page
you'll find that getElementsByName is not-so-safe-to-use no matter if
it's defined in any standard or not:

http://www.quirksmode.org/dom/w3c_core.html

(sorry, no anchors on the page... it's near the end)
 
J

Jonas Raoni

Richard Cornford escreveu:
You can reference the window object contained in an IFRAME through the
global - frames - collection, by integer index and by NAME attribute
(but not by ID attribute) in IE.

I didn't knew about it, maybe because I never used the <iframe> haha.

I just tested and both "id" and "name" worked on IE and Opera, but on
Firefox 2, it's added to the collection only if I use the name property.
A reference to an IFRAME element is not the same as a reference to the
global/window object contained in the IFRAME.

Yes, it's needed to access the contentWindow.
 
R

Richard Cornford

Jonas said:
Richard Cornford escreveu:

I didn't knew about it, maybe because I never used the
<iframe> haha.

You declared that " <iframe> doesn't behave like the <frame>, so you
won't find your <iframe> inside the "window.frames" collection" based
upon zero practical experience of applying scripting to DOM
representations of IFRAME elements? Doesn't that strike you as folly,
and likely harm you credibility?
I just tested and both "id" and "name" worked on IE and
Opera, but on Firefox 2, it's added to the collection
only if I use the name property.

And if you try it on another dozen scriptable browsers you will find
pretty much the same pattern, where an IFRAME with a NAME attribute can
reliably be referenced using that name in the containing window's -
frames - collection. It is the single most reliable approach for
referencing IFRAMEs that is arable (is unknown to fail in any scriptable
browser that can employ IFAMES in the first place.
Yes, it's needed to access the contentWindow.

But when a general strategy is available using an alternative that is
both non-standardised and only available on the newest of browsers is
acting to significantly restrict the potential of the outcome for no
good reason.

Richard.
 
R

Richard Cornford

Martijn said:
Richard said:
Martijn said:
(e-mail address removed) wrote:
window.frames['myframe'].document.
getElementsByName('mytextfield')[0].value
<snip>

getElementsByName doesn't exist in any standard. So
I wouldn't use that if I were you.
<snip>

If the W3C HMTL DOM level 1 and 2 recommendations are not
enough of a standard for you what exactly does "exist in
any standard"?
Oops, I guess I overlooked that one. But in any case, on this page
you'll find that getElementsByName is not-so-safe-to-use no matter if
it's defined in any standard or not:

http://www.quirksmode.org/dom/w3c_core.html
<snip>

There may be good reasons for not using - getElementsByName - (not least
the more reliable alternatives) but not being part of a standard is not
one of them.

Richard.
 
J

Jonas Raoni

Richard Cornford escreveu:
Jonas Raoni wrote:
You declared that " <iframe> doesn't behave like the <frame>, so you
won't find your <iframe> inside the "window.frames" collection" based
upon zero practical experience of applying scripting to DOM
representations of IFRAME elements?

Yep, I trusted in my thought :]
Doesn't that strike you as folly,
and likely harm you credibility?

Ah, I'm not looking for credibility, most of the times I answer things
without testing. It really doesn't matter what people think of me, I
don't want to look like a JS guru, I'm here mainly to spend some free
time, I just offer my knowledge and ideas ;]
And if you try it on another dozen scriptable browsers you will find
pretty much the same pattern, where an IFRAME with a NAME attribute can
reliably be referenced using that name in the containing window's -
frames - collection.

For sure, but I won't do it, I just have those 3 browsers. ^^
But when a general strategy is available using an alternative that is
both non-standardised and only available on the newest of browsers is
acting to significantly restrict the potential of the outcome for no
good reason.

Look that I didn't told the OP to use the contentWindow (if I didn't
knew about <iframes> being accessible through window.frames, I would do
it though), I just "answered" your affirmative.
 
M

Martijn Saly

Richard said:
Martijn said:
Richard said:
Martijn Saly wrote:
(e-mail address removed) wrote:
<snip>
window.frames['myframe'].document.
getElementsByName('mytextfield')[0].value
<snip>
getElementsByName doesn't exist in any standard. So
I wouldn't use that if I were you.
<snip>

If the W3C HMTL DOM level 1 and 2 recommendations are not
enough of a standard for you what exactly does "exist in
any standard"?
Oops, I guess I overlooked that one. But in any case, on this page
you'll find that getElementsByName is not-so-safe-to-use no matter if
it's defined in any standard or not:

http://www.quirksmode.org/dom/w3c_core.html
<snip>

There may be good reasons for not using - getElementsByName - (not least
the more reliable alternatives) but not being part of a standard is not
one of them.

Richard.

Of course that's a good reason. Unless you want to keep fixing your
website for every update of a certain browser made by a certain big company.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top