“[removed].hash = location.hash” does not work in Webkit (Safari & Chrome)

前端 未结 5 997
一向
一向 2021-01-12 06:14

I can\'t get window.location.hash = location.hash to work in Safari.

I\'m using javascript to wrap the contents of my page with a scrollable DIV, placed

5条回答
  •  长情又很酷
    2021-01-12 06:48

    go_hash('#home')
    

    The function...

    function go_hash(hash) {
      console.log('go_hash: ' + hash)
      if(hash.indexOf('#') == -1)
        hash = '#' + hash
      if(document.location.hash) {
        document.location.hash = hash
        return
      }
      if(window.location.hash) {
        window.location.hash = hash
        return
      }
      if(document.location.href) {
        document.location.href = hash
        return
      }
      window.location.href = hash
    }
    

提交回复
热议问题