Setting location.hash in frames

后端 未结 7 2012
清酒与你
清酒与你 2021-02-09 15:19

I am using ajax to update the location of a page in a frame. But when setting the location of the hash (on Chrome and some versions of IE (5.5) specifically, but occasionally on

7条回答
  •  一整个雨季
    2021-02-09 15:44

    You could also use HTML5 history.pushState() to change hash without reloading page in Chrome. Something like this:

    // frameset hash change function
    function changeHash(win, hash) {
        if(history.pushState) {
            win.history.replaceState(null, win.document.title, '#'+hash);
        } else {
            win.location.hash = hash;
        }
    }
    

    In the first argument you need to pass frameset top window.

提交回复
热议问题