hexadecimate

What's a wedding? Webster's dictionary describes it as the act of removing weeds from one's garden.

AJAX Navigation and a Firefox 3 JavaScript bug

I was playing around with some more AJAX navigation goodness today and ran into an interesting Firefox 3 bug.  After creating some unit tests, I grew frustrated running them in Firefox 3 and having my tests fail because the browser URL would continuously reload.

After some investigation, the culprit was determined to be a line of code similar to:

// This will cause a page reload in Firefox
document.location.hash = "";

It turns out setting document.location.hash to null or “” (empty string) will cause the current page to reload.  One workaround is to prefix all values with the “#” hash character or have a special case for null/empty strings and set the value to “#”.

// This feels completely unnecessary...
document.location.hash = (!hash || hash.length == 0) ? "#" : hash;

The workarounds are simple enough but this still feels dirty to not be able to use the location.hash property consistently across all browsers.  This behavior doesn’t reproduce in IE7, IE8, Opera 9.6 and Safari 3.1.  Just posting this out there in case anyone else is running into the same strangeness.

Posted: Oct 20 2008, 19:46 by warren | Comments (1) RSS comment feed |
  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: JavaScript | AJAX

Comments

Add comment


 

biuquote
  • Comment
  • Preview
Loading