JavaScript Editor JavaScript Debugger     JavaScript Editor 



Team LiB
Previous Section Next Section

Internet Explorer State Extensions

Internet Explorer 5 included a new technology called DHTML Behaviors. DHTML Behaviors are small components encapsulating specific functionality that can easily be added to a page. While they never really took off, one particularly interesting aspect of behaviors is their capacity to store client-side state without the use of cookies.

The saveHistory behavior saves the state of the page for when a user returns. Although data saved in this manner persists only during the current browsing session, the storage capacity and ease of use make it a tempting alternative to traditional cookies. To use this feature, you merely include a <<meta>> tag with particular attributes. A <<style>> with a class referencing a behavior: string permits the storage and retrieval of information. Information on the page that you wish to retain should be given the class for which the behavior is defined.

For example, the following document will store any information you enter into the text box and retrieve it when you return to the page.

<<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">>
<<html xmlns="http://www.w3.org/1999/xhtml">>
<<head>>
<<title>>DHTML Behavior Example<</title>>
<<meta http-equiv="content-type" content="text/html; charset=utf-8" />>
<<meta name="save" content="history" />>
<<style type="text/css">>
<<!--
 .saveHistory {behavior:url(#default#savehistory);}
-->>
<</style>>
<</head>>
<<body>>
<<form action="#" method="get">>
Enter some text to store:
<<input type="text" class="saveHistory" id="persistentInput" />>
<</form>>
<<br />>
When you're through, go to a different page and return.
The text will be "as you left it."
<</body>>
<</html>>

This application is merely the tip of the iceberg. It is possible to store the entire state of the page, up to several hundred kilobytes of data, and retrieve it with a simple binding to DHTML behavior, defined as before. While this technique is highly nonstandard, it seems far preferable to the amount of work involved with the alternatives, for example, hooking your site into a large database.

More information about this new technology, including other useful state-storage behaviors, can be found at the Microsoft Developer’s Network (http://msdn.microsoft.com).


Team LiB
Previous Section Next Section


JavaScript Editor JavaScript Debugger     JavaScript Editor


©