document.location.hash=”” sets the hash to # in the URL. But when I run this as the first thing in the DOM it doesn’t work in Firefox (at least Firefox 5.0.1). Any ideas?
Try visiting http://www.sebastianrazola.com/test.html#thisshouldberemoved in Firefox and another browser to see what I mean.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Hash test</title>
<script type="text/javascript">
document.location.hash="";
</script>
</head>
<body>
<p>The hash won't be set to <b>#</b> in Firefox. (At least in Firefox 5.0.1)</p>
</body>
</html>
It’s a bug. https://bugzilla.mozilla.org/show_bug.cgi?id=675587 to be exact (which I believe you filed).
If you want to work around this for the moment, add
document.body.offsetWidthto your script before thelocation.hashset. That will create the scrollable layout object whose non-existence causes the error that prevents the location from changing without the bugfix.