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.

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

 

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

window.parent._javaScriptVar = "someValue";

 

Source

No comments:

Post a Comment