<frame> element IE 5 methods

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

I have a variable representing a <frame> element retrieved with
document.getElementById(); let's call it foo. The document that foo
contains has a script method called bar(). How can I call bar()
through foo? In compliant browsers, I can do

foo.contentWindow.bar();

and all is well. But what in the name of holy heck do I have to do to
get IE 5.01 to do the same thing? None of the following work...

foo.all.bar();
foo.document.bar();
foo.document.parentWindow.bar();

I'm truly grasping at straws here. I'd be very grateful for a clue.
 
M

Martin Honnen

Christopher said:
I have a variable representing a <frame> element retrieved with
document.getElementById(); let's call it foo. The document that foo
contains has a script method called bar(). How can I call bar()
through foo? In compliant browsers, I can do

foo.contentWindow.bar();

and all is well. But what in the name of holy heck do I have to do to
get IE 5.01 to do the same thing?

You could go directly for the frame window object instead of for the
<frame> element object e.g. if you have
<frame name="frameName" src="whatever.html">
then
window.frames.frameName.bar()
works (in much more browsers than document.getElementById/contentWindow
works).
If you have
<frame id="frameId" src="whatever.html">
then I would guess that IE even gives you
window.frames.frameId.bar()
but that might not work in all browsers.
 
C

Christopher Benson-Manica

Martin Honnen said:
You could go directly for the frame window object instead of for the
<frame> element object e.g. if you have
<frame name="frameName" src="whatever.html">
then
window.frames.frameName.bar()

I actually can't get that to work, even in IE6...

window.frames.frameName.contentWindow.bar();

works just fine, though, which leaves me in the same situation.
then I would guess that IE even gives you
window.frames.frameId.bar()

Also does not work, nor does

document.all.frameName.bar();

, which sounds mind-numbingly reasonable to me. I'd gratefully
welcome any further suggestions, since this problem just seems too
ridiculously simple to be so difficult... *scream*
 
C

Christopher Benson-Manica

Christopher Benson-Manica said:
window.frames.frameName.contentWindow.bar();

For some absurd reason,

window.frames[1].bar();

works. Why would this work, but not

window.frames.frameName.bar();
window.frameName.bar();
document.all.frameName.bar();

? (Did I mention how much I despise IE 5?)
 
M

Martin Honnen

Christopher Benson-Manica wrote:

window.frames[1].bar();

works. Why would this work, but not

window.frames.frameName.bar();

If you really have
<frame name="frameName" src="whatever.html">
then I am sure that works (of course once the frame is loaded but that
is not different for your code in the first line)
window.frameName.bar();

That should work too as long as there are no clashes between a global
variable named 'frameName'.
document.all.frameName.bar();

That is nonsense, as said you need to distinguish between a <frame>
element object (which document.all.frameName could give you) and a frame
window object. An element object does not have the functions in the
document as its properties, only the frame window object has.
 
C

Christopher Benson-Manica

Martin Honnen said:
If you really have
<frame name="frameName" src="whatever.html">
then I am sure that works (of course once the frame is loaded but that
is not different for your code in the first line)

I did, but of course I can't produce a minimal example that does the
same thing. Never fails...
 
A

ASM

Christopher said:
window.frames.frameName.contentWindow.bar();


For some absurd reason,

window.frames[1].bar();

parent.frames[1].bar();
or
parent.myFrameName.bar();

would both work if
bar() is in 2nd frame or in frame nammed 'myFrameName'
works. Why would this work, but not

window.frames.frameName.bar();
window.frameName.bar();

which window are you targetting ? (parent ? top ? self ? )
window is 'by default' and almost egal 'self.window'
the window you need is the 'parent.window'

Do :
parent.frames['frameName'].bar();
or
parent.frameName.bar();
work for you ?
document.all.frameName.bar();

? (Did I mention how much I despise IE 5?)

IE5 knows parent.myFrame.myFunction()
 

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
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top