views:

931

answers:

2

I have an application with a launch page that needs to determine what is already opened, so it does not reopen things that are opened already in another new tab. In Firefox, I was able to make this work, by using window.sessionStorage to store the titles of pages that are open, and then use window.opener with the following code to remove the titles from the list.

Gecko Session Storage Info Page

if (window.sessionStorage) {
    if (window.sessionStorage.getItem(code)) {
        return; // page already open
    }
    else {
       window.sessionStorage.setItem(code, code);
       window.open("Sheet.aspx", "_blank");
    }
}

And on the pages that are opened:

function signalPageExit() {
    if (window.opener.sessionStorage) {

    window.opener.sessionStorage.removeItem(
     document.getElementById("runcode").childNodes[0].textContent); 
}

This doesn't work in IE so I decided to use a cookie strategy, but the cookies were never successfully deleted from code on the dynamically launched pages, and therefore pages couldn't be reopened from the launch page once they had been launched until the cookie expired.

My second attempt was to define my own sessionStorage when it did not exist. That looked like this:

    function setStoreItem(name, val) {
        this.storage[name] = val;
    }

    function getStoreItem(name) {
        return(this.storage[name]);
    }

    function removeStoreItem(name) {
        this.storage[name] = null;
    }

    function sesStorage() {
        this.storage = new storageData();
        this.setItem = setStoreItem;
        this.getItem = getStoreItem;
        this.removeItem = removeStoreItem;
    }

    // storage object type declaration
    function storageData() {

    }

    // IE 7 and others
    else {
        window.sessionStorage = new sesStorage();

        window.sessionStorage.setItem(code, code);
        window.open("Sheet.aspx", "_blank");
    }

But it seems the real session storage is special, this ordinary object of the window did not stay alive across postbacks and therefore when my launch page posted back, the list of created page titles was wiped out.

So now I'm looking for a way to make this work. I have a launch page called scoresheets.aspx that creates dynamic pages based on user requests. These pages share a substantial amount of javascript code that can be modified to make this work.

I don't want to refresh the launched pages when a user tries to reopen them, but if there is some way to detect the titles of opened pages or some other way to use window.opener to communicate with the same persistence that sessionStorage has, I'd be glad to use it.

A: 

you should go with that cookie strategy and set those cookies to expire when the windows (tab) is closed. that should work across browsers.

skrat
Cookies get sent to the server. If you have a lot of data to store, that's going to make everything really, really slow.
tghw
+3  A: 

Eric Garside’s jStore plugin provides a jquery based api to several client side storage engines.

Lachlan Roche
I went ahead and set up jStore, but I'm getting an error internally in the Jstore javascript. I filed an issue on google code, so hopefully I can figure out what is going wrong there.
Tony Peterson
I have not tried the flash engine myself. I just checked the ie engine (#userdata) and it works on ie6 through ie8.
Lachlan Roche