473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

FireFox/Netscape location.hash to empty string --> infinite loop


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>

Wish I'd known 4 hours ago....

Stewart

Aug 19 '05 #1
3 3077
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.

Aug 19 '05 #2
Lee
Stewart said:


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.


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.

Aug 19 '05 #3
I am?

I was wanting it to scroll down to the <a name="anchorRef">Interesting
bit</a>

I thought location.assign(), location.reload() and location.replace()
were commands to reload the page.

The reference I looked up (www.w3schools.com) said: "hash - Sets or
returns the part of the href property that follows the hash sign (#)"

I guess though if window.location = 'http://new_url'; causes a page
reload, then setting the hash might do so also.

Fair enough.

Aug 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Yimin Rong | last post by:
Does anyone know if there are any browsers where you must specify "#" as a prefix when setting the hash for the location? For example, the following would move to the intro section of the...
7
by: User | last post by:
Hi, A page I have shows a different background colour depending on the hash portion of the url as it is first loaded. For example a link to mysite/mypage#0000FF would result in a page with a blue...
1
by: Jim P. | last post by:
I'm having trouble returning an object from an AsyncCallback called inside a threaded infinite loop. I'm working on a Peer2Peer app that uses an AsyncCallback to rerieve the data from the remote...
4
by: David Bargna | last post by:
Hi I have a problem, I have a string which needs to be converted to a byte array, then have the string representation of this array stored in an AD attribute. This string attribute then has to...
2
by: scottys0 | last post by:
Hi everyboy, I'm working in an IOC-IBM (IBM open class) replamecent library. the code seens confused but , no, isn't. #define INumber long class IString : public std::string { private:...
19
by: Richard | last post by:
Hi All, I copied a script example from http://www.irt.org/script/640.htm into a local .html file. I opened that file first in HTML-kit, which hung (in an infinite loop, I think) when I...
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
2
by: Lawrence Krubner | last post by:
Imagine a template system that works by getting a file, as a string, and then putting it through eval(), something like this: $formAsString = $controller->command("readFileAndReturnString",...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.