Replacement for window.sessionStorage in Javascript?

I have an application with a start page that needs to detect what is already open, so it does not open functions that are already open in another new tab. In Firefox, I was able to get the job done using window.sessionStorage to keep the titles of the open pages and then use window.opener with the following code to remove the titles from the list.

Gecko Session Save Information 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 open pages:

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 the cookie strategy, but the cookies were never successfully removed from the code on dynamically launched pages, and therefore the pages could not be reopened from the launch page once they were started before the cookie expired ...

My second attempt was to define my own sessionStorage when it doesn't exist. It 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 looks like the real session store is special, this regular window object didn't survive on the back side and so when my start page was sent back the list of page titles that had been created was destroyed.

So now I am 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 contain a significant amount of javascript code that can be modified to make this work.

I don't want to refresh running pages when the user tries to reopen them, but if there is a way to detect the headers of the open pages, or some other way to use window.opener to communicate with the same persistence as sessionStorage, I'd be happy to use it.

+1


a source to share


2 answers


Eric Garsides The jStore plugin provides jQuery based on jQuery for multiple client storage systems.



+3


a source


you should go with this cookie strategy and set these cookies to expire when windows (tab) is closed. which should work in browsers.



-1


a source







All Articles