Activate your free membership today | Log-in

Wednesday, September 24th, 2008

Ex DOM Storage gives us hope for IE 6+

Category: Browsers, IE

Toru Yamaguchi has built a very cool shim, ExDOMStorage, which implements the HTML 5 DOM Storage API for IE 6 and 7.

It does so by strapping in the functionality via an HTC behaviour:

JAVASCRIPT:
  1.  
  2. (function() {
  3.    if (window["localStorage"] && window["sessionStorage"])
  4.          return;
  5.  
  6.    with({ nodeSet: document.getElementsByTagName("script"), storages: ["localStorage", "sessionStorage"] }) {
  7.          var loader = nodeSet.item(nodeSet.length - 1);
  8.          var src = loader.getAttribute("src");
  9.          var behavior_uri = src.replace(/\/\w+\.js$/, '/exdomstorage.htc');
  10.  
  11.          for (var i in storages) with ({ storage: document.createElement('script'), name: storages[i] }) {
  12.            window[name] = storage;
  13.            loader.parentNode.appendChild(storage);
  14.            storage.addBehavior(behavior_uri + "#" + name);
  15.          }
  16.    }
  17. })();
  18.  

Posted by Dion Almaer at 7:38 am

+++--
3.2 rating from 26 votes

3 Comments »

Comments feed TrackBack URI

U could also store data using window.name… session wise.. IE6 (sp3+) handles it fine…

but that looks hot to :P

Comment by V1 — September 24, 2008

Just a side note (not a competitive one); MooTools has something similar that it calls “Element.Storage”. Just FYI.

Comment by anewton — September 24, 2008

This is something I was planning to build when I had the time so thank you Toru Yamaguchi. Much better solution than what I had in mind (Flash ShareObjects.

Buddy - Graphic Designer from Katy, TX

Comment by mydesignbuddy — September 25, 2008

Leave a comment

You must be logged in to post a comment.