function UserDataStorage(maxage) { // Create a document element and install the special userData // behavior on it so it gets save() and load() methods. var memory = document.createElement("div"); // Create an element = "none"; // Never display it = "url('#default#userData')"; // Attach magic behavior document.body.appendChild(memory); // Add to the document // If maxage is specified, expire the userData in maxage seconds if (maxage) { var now = new Date().getTime(); // The current time var expires = now + maxage * 1000; // maxage seconds from now memory.expires = new Date(expires).toUTCString(); } // Initialize memory by loading saved values. // The argument is arbitrary, but must also be passed to save() memory.load("UserDataStorage"); // Load any stored data this.getItem = function(key) { // Retrieve saved values from attributes return memory.getAttribute(key) || null; }; this.setItem = function(key, value) { memory.setAttribute(key,value); // Store values as attributes"UserDataStorage"); // Save state after any change }; this.removeItem = function(key) { memory.removeAttribute(key); // Remove stored value attribute"UserDataStorage"); // Save new state }; }
Implements the getItem(), setItem(), and removeItem() methods of the Storage API on top of IE’s userData. (It does not implement key() or clear(), because userData does not define a way to iterate through all stored items.)

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.