Untitled

 avatar
unknown
plain_text
a year ago
1.1 kB
4
Indexable
(function(history) {
        var pushState = history.pushState;
        var replaceState = history.replaceState;
        history.pushState = function(state) {
            if (typeof history.onpushstate == "function") {
                history.onpushstate({state: state});
            }
            handleNavigation();
            return pushState.apply(history, arguments);
        };
        history.replaceState = function(state) {
            if (typeof history.onreplacestate == "function") {
                history.onreplacestate({state: state});
            }
            handleNavigation();
            return replaceState.apply(history, arguments);
        };
    })(window.history);

    // Listen for popstate event (back/forward navigation)
    window.addEventListener('popstate', handleNavigation);

    // Listen for hashchange event (URL hash changes)
    window.addEventListener('hashchange', handleNavigation);

    // Listen for click events on links
    document.addEventListener('click', function(event) {
        if (event.target.tagName === 'A' && event.target.href) {
            handleNavigation();
        }
    });
Editor is loading...
Leave a Comment