Saturday, July 19, 2008

Persisting data in a web app by using frames


Say you have your main page, which is just a frameset. All the navigation occurs within that frameset, such that going from page1 to page2 merely updates the frame's url, it doesn't re-create the host page. This leaves the host page intact, including it's JavaScript state. Therefore, you could have a JavaScript variable persist data between pages.

    <title>My App</title>
    <script language="javascript" type="text/javascript">
      var _javaScriptVar = null;
      <frame src="Page1.aspx" id="mainFrame">


You could then reference this variable from your child pages via the DOM:

window.parent._javaScriptVar = "someValue";



No comments:

Post a Comment