Webshims Lib

Polyfill only the incapable browsers

Demo/About/Documentation JSON and localStorage/sessionStorage

The json-storage feature implements JSON.parse/stringify via JSON2 script and localStorage/sessinStorage.

The Storage support is based on the storage polyfill by Remy Sharp. It uses the window.name-trick to store data for the session and shared object (flash) or a cookie (only, if flash isn't available) for localStorage.

The following Storage-interface is implemented:

  • setItem
  • getItem
  • removeItem
  • clear
  • key

If the flash localStorage shim is used and the the storage limit is hit, the flash settings dialog will be placed in to view to request more space for the storage. If the user denies this a DOMexception will be raised (QUOTA_EXCEEDED_ERR: 22).

Note: That IDL-attributes and the length property aren't implemented. You shouldn't rely on them, anyway.

Note: To use localStorage/sessionStorage you should test your webapp/website in an http-enivroment.

Note: For flash localStorage-polyfill: Add your development-directory to the local-trusted security sandbox.

$(function(){ if(localStorage.getItem('do-i-know-you') !== null){ //yes } else { //but now try { localStorage.setItem('do-i-know-you', 'yes'); } catch(e){} } });

Options for the swf localStorage (json-storage feature)

  • exceededMessage (string): A message, that will be placed above the flash settings dialog, which informs the user to allow more storage space for your domain.
$.webshims.setOptions("json-storage", { exceededMessage: "This application needs more space. Please move the slider to 5MB." }); //$.webshims.polyfill();

Changing path to swfobject

$.webshims.modules.swfobject.src = "/path/to/swfobject.js";