spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column24


Hard Disk Persistence

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

Internet Explorer 5.0 introduces saveSnapshot, a Behavior that enables persistence of an HTML file when you save it onto your hard disk. This Behavior is specifically targeted towards persistence of form data, as explained below. Let's practice it a little so you understand the power behind it.

Let's try to save this form to your hard disk. Select the Save As option from the form window's File menu. Choose HTML Only file type. Now, load back this file to your browser, by any convenient way you use to load HTML files. Notice that one field has kept its entry, while the other one did not. You have just witnessed the power of the saveSnapshot Behavior. We explain next how to implement it.

There are a few changes you have to make in your Web page to be able to use persistence Behaviors. First, you have to add the following META tag:

<META NAME="save" CONTENT="snapshot">

Secondly, you need to define the saveSnapshot Behavior as a built-in one:

<STYLE>  
  .saveSnapshot{behavior:url(#_IE_);}
</STYLE>

You can persist your form in any level you want. First, you can persist individual entries, as we have just demonstrated. Here is the body of our example:

<BODY>
<FORM>
Enter a text you want to be persisted: 
<INPUT TYPE="text" CLASS="saveSnapshot" ID="inputPersistText">
Enter a text you don't want to be persisted: 
<INPUT TYPE="text">
</FORM>
</BODY>

In order to enable a persistent element, you need to specify its Behavior via the CLASS attribute, and assign an ID to the element. Notice how easy it is to implement this persistence. You don't have to explicitly define attributes and store data in them. It's all being taken care of by the saveSnapshot Behavior.

You can also persist an entire form by assigning the saveSnapshot Behavior to the FORM element:

<BODY>
<FORM> CLASS="saveSnapshot" ID="inputPersistText">
Enter a text you want to be persisted: 
<INPUT TYPE="text">
Enter another text you want to be persisted: 
<INPUT TYPE="text">
</FORM>
</BODY>

The third element you can hard-disk persist is form data in a script block. Only variables will be persisted. Comments, functions, and object such as arrays are not included. Let's take our previous example and modify it to persist a variable:

<BODY>
<SCRIPT CLASS="saveSnapshot" ID="persistentScript">
  var persistentVariable;
</SCRIPT>
<FORM>
Enter a text you want to save:
<INPUT TYPE="text" ID="inputText">
Click to save: 
<INPUT TYPE="button" VALUE="save" onclick="persistentVariable=inputText.value">
Click to load:
<INPUT TYPE="button" VALUE="load" onclick="inputText.value=persistentVariable">
</FORM>
</BODY>

Here, the only persistent element is the persistentVariable variable, or any variable put inside the persistentScript script. We ask the user to enter some text and then click a button to save it in the persistent variable. When the user saves the file onto his or her hard disk and then reload it, clicking on the "load" button will refresh the form entry with the persistent variable. To be convinced, play around with the text entry field and do not save it. When you reload the file from disk, you will extract the text you had explicitly saved and not the one last entered.

Notice we have not used our Connect Three game example to demonstrate the saveSnapshot Behavior. The reason is that this behavior is targeted to support FORM elements only, as opposed to out IMG elements in our board game.

http://www.internet.com

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Crucial Triples Up With New Three-Channel DDR3 Kits · Meet the Finalists: Excellence in Technology Awards · Tealeaf Offers Insight to Mobile Customer Behavior


Created: August 28, 1998
Revised: August 28, 1998

URL: http://www.webreference.com/js/column24/snapshot