Setting location.hash in frames

后端 未结 7 2017
清酒与你
清酒与你 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:34

    for chrome and safari, you need to use window.location.href to get the hash working rather than window.location.hash

    see code below

    function loadHash(varHash)
    {
      if(varHash != undefined) {
        var strBrowser = navigator.userAgent.toLowerCase();
    
        if (strBrowser.indexOf('chrome') > 0 || strBrowser.indexOf('safari') > 0) {
            this.location.href = "#" + varHash;
        }
        else {
            this.window.location.hash = "#" + varHash;
        }
      }
    }
    

提交回复
热议问题