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

/whatever/page/1#encodeddata

to

/whatever/page/2#encodeddata

So what i did was:

window.location.pathname = url_page_replace(window.location.pathname, parseInt(obj.page)) + 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:

/whatever/page/2%23encodeddata

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(obj.page)) + 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 :- )

Comments

Post new comment

Image CAPTCHA

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! Drop me a line or leave a comment.

Follow my RSS