Window location hash difference in FF3 and Opera

I was working on the back button support and bookmarkability of one of my galleries and by accident i have noticed there is a slight difference in behavior.

I wanted to change the url to differnet page but preserving the hash at the same time.

I wanted to jump on some event from page




So what i did was:

window.location.pathname = url_page_replace(window.location.pathname, parseInt( + window.location.hash;

I thought if i replace the path and append the hash to it everything would be cool but there is a difference. Opera and Chrome in such situation assume that i only wanted to change the path and they think i have put # hash just by accident. What they do is actually url encode that hash so when i get redirected i hit this page instead:


Little goole lookup on hash and window location made me realize my mistake.

What is the difference between window.location.pathname and window.location

If you override the full url by changing window.location than browser knows you want to change the url to the new one with hash string in it and there is no urlencoding added.

So what worked looked like this:

window.location = 'http://'+ domain + url_page_replace(window.location.pathname, parseInt( + window.location.hash;

The funny bit is that IE8, FF3 and Safari do not do this escaping so i thought it was some more serious problem :-)

I actually got the hint by looking at this page about window.location

Funny but true :- )


Post new comment


About the author

Artur Ejsmont

Hi, my name is Artur Ejsmont,
welcome to my blog. I am a passionate software engineer living in Sydney and working for Yahoo!

Web Scalability for Startup Engineers

If you are into technology, you can order my book Web Scalability for Startup Engineers on Amazon. I would love to hear what are your thoughts so please feel free to drop me a line or leave a comment.

Follow my RSS