FireFox/Netscape location.hash to empty string --> infinite loop
Stewart 19 August 2005 22:19:11
Dear javascripters,
Through a frustrating afternoon of debugging I appear to have discovered something:
Setting location.hash to an empty string in the global namespace (not inside a function) Mozilla/FireFox/Netscape causes the browser to go into an infinite loop, apparently attempting to reload the page. ie: <script type="text/javascript"> <!-- // DON'T DO THIS!! this.document.location.hash = ''; //--> </script>
I'm surely not the only one to have discovered this, but I didn't find any references to it upon searching the web.
It works fine in IE6, behaving identical with: this.document.location.hash = '#';
So do that, or put it in a function, and control when the function gets called.
Or, as I'm creating this script on the fly in a JSP, don't produce that code if the reference is empty or null: <logic:notEmpty name="anchorRef"> this.document.location.hash = '<bean:write name="anchorRef"/>'; </logic:notEmpty>
Through a frustrating afternoon of debugging I appear to have>discovered something:>
Setting location.hash to an empty string in the global namespace (not>inside a function) Mozilla/FireFox/Netscape causes the browser to go>into an infinite loop, apparently attempting to reload the page.
I don't understand why you would expect it to do anything else. By setting the hash attribute, you're telling the browser to reload the page.
OK, so it's happening in IE6 too, but under different circumstances. Clicking on a link refering back to this page is sending it into an infinite loop, but not sure what's wrong with the link at this point. But commenting out the location.hash = definitely stops it happening.
If you would like to report an abuse of our service, such as a spam message, please . Если Вы хотите пожаловаться на содержимое этой страницы, пожалуйста .