window.parent.frames don't work in Firefox

2019-09-20 15:53发布

问题:

alert(window.parent.frames.toolbar.location)

the alert is undefined in Firefox, IE it work fine.

回答1:

In Chrome and FF there's a difference if toolbar is either an id or a name of an (i)frame. .frames.id will refer to an actual (i)frame element (which doesn't have location property), .frames.name refers to the window within an (i)frame element. In IE both refer to the window within (i)frame.

A quick-fix would be to add also/use only name="toolbar" attribute to your (i)frame element.



回答2:

Use this

alert(window.parent.frames[0].toolbar.location);

That should work.

As my comment said. window.frames is a list containing all frames in a window. You need to select the correct window, which I guess is the one with index 0.