devote / HTML5-History-API

HTML5 History API expansion for browsers not supporting pushState, replaceState
http://spb-piksel.ru
MIT License
1.02k stars 182 forks source link

To maintain the state of object on URL in IE/Edge #107

Open mveer-agarwal opened 6 years ago

mveer-agarwal commented 6 years ago

I have modified the firePopState method by adding a Map, which keeps the URL and state of object in case of IE/Edge.

function firePopState(currentUrl) {
        var o = document.createEvent ? document.createEvent('Event') : document.createEventObject();
        var currentUrl = currentUrl;
        var NextUrl = windowLocation.href;

        if (o.initEvent) {
            o.initEvent('popstate', false, false);
        } else {
            o.type = 'popstate';
        }

        if (historyMap[NextUrl]) {
            o.state = historyMap[NextUrl];
            delete historyMap[NextUrl];
            historyObject.replaceState(null, "", NextUrl);
        } else {
            historyMap[currentUrl] = historyObject.state;
        }
        // o.state = historyObject.state;
        // send a newly created events to be processed
        dispatchEvent(o);
    }

Please suggest.