473,703 Members | 3,140 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.l ocation.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.l ocation.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:notEmp ty name="anchorRef ">
this.document.l ocation.hash = '<bean:write name="anchorRef "/>';
</logic:notEmpty>

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

Stewart

Aug 19 '05 #1
3 3096
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 ">Interesti ng
bit</a>

I thought location.assign (), location.reload () and location.replac e()
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
9916
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 document: window.location.hash = "#intro"; But in the same browser, this would not work:
7
16517
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 background. But another link, this one to mysite/mypage#FF0000, would not give me a red background if directed to the window where mypage#0000FF was loaded just one moment ago. This is normally to be expected, because the browser thinks same...
1
5220
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 peer. I have no problem connecting the peers and streaming Network Streams. When the incoming data is finished recieving, I act upon it. This works great as long as all of the code is inside my form. I want to build the networking code into a...
4
13405
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 be read and the string representation of the byte array has to be converted back to the original byte array and converted back to the original string - confused yet? in psuedo
2
4208
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: ... // some control variables
19
2347
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 previewed the example. On the off chance that example exposed a weakness in HTML-Kit, I ran the example in IE7, which also hung. The example seems to start an infinite loop which the user should be
44
4320
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
3222
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", $formName); // 06-22-07 - the next commands try to import all the functions that the
0
8761
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8672
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9257
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7876
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6594
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4434
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3125
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.