Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Potential problems setting window.location.hash

Tags:

I have some javascript code which, at one point, sets window.location.hash to a specific string. This works fine in Firefox 3, but I want to know if I will run into problems with this later, i.e. is this a cross-browser solution (IE6 included)?

Also, I am using ReallySimpleHistory. Will this mess up its internal state?

Thanks

like image 966
Cameron Avatar asked Aug 11 '09 23:08

Cameron


2 Answers

window.location.hash has been around since JavaScript was introduced in Netscape Navigator 2 back in 1995. It was first supported by Microsoft in Internet Explorer 3 in 1996. I think you can be reasonably certain that every JS-capable browser supports it.

From a quick glance through the source, it looks as if ReallySimpleHistory makes pretty extensive use of this property, so you may well break it. You might want to use its add(newLocation) method instead (which works by setting window.location.hash).

like image 79
NickFitz Avatar answered Oct 07 '22 16:10

NickFitz


Get:

 var hash = location.hash.slice(1); 

Set:

 location.hash = '#' + 'string'; 
like image 38
Thinker Avatar answered Oct 07 '22 16:10

Thinker