PDA

View Full Version : js: external scope?


forlamp
04-14-2004, 01:18 PM
Hey, ok so if i create a frameset with 2 frames, and in the frameset definition file.. i.e index.html, if i define javascript functions are they inherited to BOTH children (h.html & m.html for arguements sake).

-fl

agent002
04-14-2004, 01:29 PM
you can call them from the children (the frames) using parent., i.e. if index.html has a function called doStuff(), and you want to call it from h.html, use
parent.doStuff();
Please notice that if the pages are located on different domains, you will get a JavaScript error message saying security error or something.

forlamp
04-14-2004, 02:09 PM
ok, so if i have some variables and a function or two in the parent, both children can access it via parent.* .. good...

now will the parent keep all the variables if say h.html navigates to a diff page?

-fl

agent002
04-14-2004, 02:17 PM
yes! lucky you :D

You can define a variable in index.html, like
var passData;

Then, in h.html, set parent.passData to some value. You can access that value from the second frame; from m.html. Or you could load another page to one of the frames, like x.html... you can still access parent.passData :)

Other ways of passing data would be the query string (filename.html?key=value), or cookies.

forlamp
04-14-2004, 02:19 PM
yeah, query string and cookies wont work for this scenerio.. but that information was very helpful!

-fl