I have two iframes and each iframe show two different html pages. Both html pages refer to a common javascript file which contains a global variable. If I set the value of that global variable in one frame during html page load. Will the value be accessible using the same global variable to another iframe html page? why or why not?
+5
A:
No. The top level of JavaScript's scope space is the page level. However, you can access another page's scope by using window.parent
Rex M
2009-03-16 13:27:04
@Deepak feel free to click the "Check" to accept the answer if it solves your problem or answers your question.
Rex M
2009-03-16 13:30:19
Alas, he cannot accept your answer until he has a reputation of 10. Which he does now, since I up-voted his question.
Benry
2009-03-16 16:55:06
Maybe this is no longer true. Was once.
Benry
2009-03-16 16:56:54
A:
Actually I'm noticing it doesn't seem to maintain scope and maybe someone can shed light on this.
Example 1: You have a HTML page with some Flash Content that has some functions to get the SWF Object and fire a command. When this page is loaded into a IFRAME the 'getSWFObj' is "not a function".
Example 2: I load a HTML Page that has a series of object based JavaScript files. I create a instance called "player" and it creates some sub objects like "navigation". When I call "player.navigation" I get a error saying it doesn't exist when loaded into a IFRAME.