Running document.location.hash = "" as first thing in DOM doesn't clean the URL
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). A开发者_开发技巧ny 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.offsetWidth
to your script before the location.hash
set. That will create the scrollable layout object whose non-existence causes the error that prevents the location from changing without the bugfix.
精彩评论