views:

543

answers:

1

I have a web page which contains a JavaScript variable called "myVariable".

Within this web page is an iframe which points to a second web page.

Both pages are within the same domain.

The page within the iframe needs to access "myVariable" which is defined in the parent web page.

I have successfully accessed this variable with Firefox using the following code:

document.defaultView.parent.myVariable

However, this does not work in Internet Explorer.....

How do I do this in Internet Explorer?

+2  A: 

If both pages are from the same domain (like you say), window.top or window.parent should work to get to the parent frame.

window.top.document.myVariable
Thilo
Yep - just discovered window.yop myself - thought it was IE only, but firefox supports it as well so I've been able to remove branching code too. Thanks for your help.
ListenToRick