"window.location.hash = location.hash" does not work in Webkit (Safari & Chrome)

Viewed 37283

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 below the navigation bar in my webpage. Since the scrollbar's location gets reset when the javascript runs, I'm losing the original hash location that the URL set. I need to re-cue the hash location without reloading the page using javascript, so I'm using window.location.hash = location.hash. It works in IE8, Firefox, and Opera, but it doesn't work in Safari. (I'll assume Chrome, too, but I haven't check). Any suggestions?

Hint: I like jQuery.

5 Answers
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
}
Related