localstorage popupWIndow

This is to demonstrate saving the win array to local storage. However it doesnt seem to keep the reference

by thorst

JavaScript

/*!
* Display popup window.
*
* Requires: jQuery v1.3.2
*/
(function($) {
  var defaults = {
    center:      true,
    createNew:   true,
    height:      500,
    left:        0,
    location:    false,
    menubar:     false,
    name:        null,
    onUnload:    null,
    resizable:   false,
    scrollbars:  false, // os x always adds scrollbars
    status:      false,
    toolbar:     false,
    top:         0,
    width:       500,
    forcerefresh:false,
      localStorage: true
  };

  $.popupWindow = function(url, opts) {
    var options = $.extend({}, defaults, opts);

    // center the window
    if (options.center) {
      // 50px is a rough estimate for the height of the chrome above the
      // document area
      options.top = ((screen.height - options.height) / 2) - 50;
      options.left = (screen.width - options.width) / 2;
    }

    // params
    var params = [];
    params.push('location=' + (options.location ? 'yes' : 'no'));
    params.push('menubar=' + (options.menubar ? 'yes' : 'no'));
    params.push('toolbar=' + (options.toolbar ? 'yes' : 'no'));
    params.push('scrollbars=' + (options.scrollbars ? 'yes' : 'no'));
    params.push('status=' + (options.status ? 'yes' : 'no'));
    params.push('resizable=' + (options.resizable ? 'yes' : 'no'));
    params.push('height=' + options.height);
    params.push('width=' + options.width);
    params.push('left=' + options.left);
    params.push('top=' + options.top);

    // define name
    var random = new Date().getTime();
    var name = options.name || (options.createNew ? 'popup_window_' + random : 'popup_window');

    // get existing win handle if exists
    if (!$.popupWindow.win) {
        //instead of empty, load from localstorage
        if (!window.localStorage) {
            $.popupWindow.win = [];
        } else {
            var lsWin =localStorage.getItem("popupWindow.win");
            $.popupWindow.win = lsWin===null ? [] : JSON.parse(lsWin);
           ...