Setting window.location.hash to null in Safari 3+ makes it set to #

Setting window.location.hash to null in Safari 3+ makes it set to #, eg.

window.location.hash = '#foo' => #foo

But,

window.location.hash = null => #

The same happens if you set it to an empty string instead of null. The behavior definitely happens in Safari 3 + 4 and doesn't occur in FF 3 or 4.

Any workarounds for this? Sure, this is more of an aesthetically motivated thing, but I still like the consistent behavior across all browsers.

+2


source to share


2 answers


In Safari 4 (don't know about 3) this will cause the # to disappear and the page won't reload.

window.location.hash = 'foo';
window.history.go(-1);

      



However, this will obviously mess up your browser history. If they click forward, they will move them to http://whatever.com/#foo .

0


source


Set the hash to an empty string, not zero. Null is not a valid value for the hash property (which is always a string). Works for me in Safari 3.2.1 / Win. (Although not, for some reason in Opera 10 ... but then who cares? Does the empty hash part at the end of the URL have such a bad thing?)



0


source







All Articles