View Full Version : Public Variables
russ801
05-30-2003, 09:24 PM
If I declare a variable in an external js file , is that var availible to all the pages?
ACJavascript
05-30-2003, 09:37 PM
Yes, but if your thinking like changing the variables dynamicly in one page and it having effect on another that wont work.
russ801
05-30-2003, 09:49 PM
My concept is to populate the variable with the page name and do some formatting with that if the page is refreshed.
cheesebagpipe
05-31-2003, 12:42 AM
This has to do with persistence (cross-document), not scope. A so-called 'external' JS file is nothing more than JavaScript, stored separately from the .html files it's used with. No special properties.
russ801
06-01-2003, 09:02 PM
I am not sure how I will use it but this works
declaring a var in the external js file:
var x='test'
can be used by the rest of the site by refernencing it as
top.x
Roy Sinclair
06-02-2003, 08:23 PM
That only works if the whole site is served inside a frameset. The "top" object refers to the containing frame which is a good place to store settings to be saved between pages that are loaded into the frame. There are also some problems with that though, if a user presses their "refresh" button on their browser all those settings that were set up by pages that are no longer being viewed are definitely going to go awol. If you need variables to hang around longer you should be looking at storing them into a cookie.
russ801
06-02-2003, 08:32 PM
I do use a frameset and had neglected to test it in a non frames environment.
And it is the reset button which is giving me the problem, with the problems you have listed.
Its been an education.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.