browser back button is not updating page

后端 未结 3 752
说谎
说谎 2021-01-28 21:08

I\'m setting the URL after the hashmark with a jquery click event. The URL is getting set properly but when I use the browsers back button it doesn\'t take me to the previous p

3条回答
  •  北海茫月
    2021-01-28 21:47

    You could code something like this:

    var _hash = '';
    
    function myHashChangeCallback(hash) {
        // handle hash change
        // load some page using ajax, etc
    }
    
    function hashCheck() {
        var hash = window.location.hash;
        if (hash != _hash) {
            _hash = hash;
            myHashChangeCallback(hash);
        }
    }
    
    setInterval(hashCheck, 100);
    

提交回复
热议问题