7

I was wondering whether the javascript objects kept accross pages? Looks like some browsers do and some dont. What is the standard behavior?

Thanks, Ebe

5
  • They are not supposed to be kept, it's not a normal browser behavior. Commented Jun 19, 2009 at 22:06
  • As an interesting aside, how do you all think the programming model for RIA's would change if this behavior were implemented in browsers? (At least maintaining state per domain, and clearing it once a user browses away) Commented Jun 19, 2009 at 22:19
  • 1
    Somewhat similar behavior is coming in HTML 5 which has a local storage API (pretty much a relational database in the browser). A bunch of the browsers already support this API (I know the newest versions of Safari and Firefox do) Commented Jun 19, 2009 at 22:26
  • That's really good to hear; HTML 5 is shaping up to be a plugin killer (and I just took the effort to learn Silverlight!!) Commented Jun 19, 2009 at 22:33
  • @Ebe that makes no sense, If all the created objects from all pages were kept your memory would soon fill and blew up. What possible advantages would a system gain from such a mess. Would it help if when you opened a new document in word, it kept the old one and merged the two? Commented Jun 19, 2009 at 22:43

4 Answers 4

9

No, all objects will be lost when you change pages.

However, there is an interesting hack you can do with window.name. The value of window.name will remain for as long as the current window is open, so you can store data in it temporarily (and access it from page-to-page). However this data is accessible (and overwritable) from any page using that window, so it's not secure or reliable storage.

See http://www.thomasfrank.se/sessionvars.html for more info.

Sign up to request clarification or add additional context in comments.

Comments

2

Browsers do cache script files but the scope of JavaScript objects is limited to the page into which the script file is loaded, so that if you navigate to another page that uses the same script, the objects will be freshly created but not necessarily have the same state as in the previous page.

1 Comment

Okay, so say I have a page which creates an object with some data in it. The user is navigated to another web page, what methods are available to retrieve that data?
2

Never seen such a behavior. As far as i know - there aren't browsers that do this.

Comments

-2

Some web browsers such as Safari cache the compiled javascript code. But state should not be persistent across page loads under any browsers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.