Window.location in IE6 doesn't work

Hi there,

I’m having trouble with window.location in IE6 for a few days now.
I made an online file manager for my CMS. The JavaScript is used to redirect to a filehandler, based on the extension of the file one wants to open.

Last week I’ve been testing it in following browsers, and everything worked fine at that time:
-Internet Explorer 5.5
-Internet Explorer 6.0
-Internet Explorer 7.0 (through the updates of Microsoft)
-Mozilla Firefox 1.0
-Mozilla Firefox
-Mozilla Firefox
-Mozilla 1.8b
-SeaMonkey 1.0.6
-Netscape 8.0.2 (tested in both engines: IE and FF)
-Opera 8.0
-Opera 9.1
-K-meleon 1.02
-Konqueror 3.5.2

Yesterday I had to represent this to a client, and suddenly none of the commands seemed to work.

Because the whole script was rather long, and could contain an error that makes window.location do nothing, I did some research when I got home and made a test-page.

You should take a look at this documentation before giving me advice or solutions, because I think I tried it all…
-location Object

This is the test-page:
<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1”>
<title>Untitled Document</title>
<script language=“javascript” type=“text/javascript”>
function OpenLocation()
window.location = ‘’;

function OpenLocationHref()
	window.location.href = '';

function OpenLocationIntern()
	window.location = 'redirected.html';

function OpenLocationInternHref()
	window.location.href = 'redirected.html';

function OpenNavigate()

function OpenNavigateIntern()

<a href=“javascript:;” onClick=“OpenLocation();”>Google</a><br/>
<a href=“javascript:;” onClick=“OpenLocationHref();”>Google HREF</a><br/>
<a href=“javascript:;” onClick=“OpenNavigate();”>Navigate Google</a><br/>
<a href=“javascript:;” onClick=“OpenNavigateIntern();”>Navigate Intern</a><br/>
<a href=“javascript:;” onClick=“OpenLocationIntern();”>Intern</a><br/>
<a href=“javascript:;” onClick=“OpenLocationInternHref();”>Intern HREF</a><br/>
<a href=“javascript:;” onclick=“window.location = ‘’;”>Inline</a><br/>
<a href=“javascript:;” onclick=“window.location.href = ‘’;”>Inline HREF</a>

This test-page works in all the browsers, except Internet Explorer 6.
I tried every doc-type, I tried every JavaScript version in the script-tag, I tried the script-tag without any attributes, I tried to enclose the JavaScript-code with <!-- –>, … you name it…

I’ve got serveral computers at hand, one has automatic updates disabled, so that computer did not receive any updates from Microsoft.
Even on the untouched IE6 this test-page doesn’t work.
All the other browsers have no problem with redirecting.

The window.location.reload(boolean) does work, and alert(window.location) works perfect too.

The weird thing about this whole thing is that none of the browsers give warnings, errors or whatever, not even IE6.

Anyone suggestions or maybe a solution?


I notice a few of your assignments lack the href part of the window.location.href object property.

IE doesn’t like “javascript:”, which is unnecessary anyway. Here’s your corrected html:

<a href="[color="green"]noJS.htm[/color]" onClick="OpenLocation(); [color="green"]return false;[/color]">Google</a><br/>
<a href="[color="green"]noJS.htm[/color]" onClick="OpenLocationHref(); [color="green"]return false;[/color]">Google HREF</a><br/>
<a href="[color="green"]noJS.htm[/color]" onClick="OpenNavigate(); [color="green"]return false;[/color]">Navigate Google</a><br/>
<a href="[color="green"]noJS.htm[/color]" onClick="OpenNavigateIntern(); [color="green"]return false;[/color]">Navigate Intern</a><br/>
<a href="[color="green"]noJS.htm[/color]" onClick="OpenLocationIntern(); [color="green"]return false;[/color]">Intern</a><br/>
<a href="[color="green"]noJS.htm[/color]" onClick="OpenLocationInternHref(); [color="green"]return false;[/color]">Intern HREF</a><br/>
<a href="[color="green"]noJS.htm[/color]" onclick="window.location = ''; [color="green"]return false;[/color]">Inline</a><br/>
<a href="[color="green"]noJS.htm[/color]" onclick="window.location.href = ''; [color="green"]return false;[/color]">Inline HREF</a>

Interesting window.navigate works for you in gecko based browser?

I notice a few of your assignments lack the href part of the window.location.href object property.

Read this: location Object

Interesting window.navigate works for you in gecko based browser?

Mirek, thanks for noticing, but that’s not the point exactly.
I know window.navigate() is IE-only.

7stud, I’ve tried that all. None of it works, even with return false; and so on.

This is how it should work:
In the filemanager I’ve got a contextmenu (not supported in Opera).
The contextmenu has these menuitems: Open, Edit, Download, Copy, Paste, Move, Rename, Remove and Properties.
Every menuitem has a command attached.
A menuitem looks like this: <a href=“javascript:;” onclick=“CommandName();”>MenuItem</a>
Note: here you DON’T need return false;
This is a command-function:
function CommandName()
//activeFile is the file that is selected by right-clicking it
var filename = activeFile.getAttribute(‘filename’);
//The code to handle the command, for example opening the filehandler
var handler = activeFile.getAttribute(‘handler’);
if (handler == ‘’ || handler == ‘undefined’) {
alert(‘There is no program found to open this file.’);
else { handler + ‘?filename=’ + filename );

This should work, IE doesn’t show any errors, or whatever.
If there was an error, IE or another browser in the list would give an error anyways.

Right now I’m considering to give the file an attribute with the whole URL to redirect to, if neccessary. And instead of using in the script, just replacing the href-tag of the menuitem with the URL and return true;
That should work too, in theory though.

I should start a revolution against IE-developers and make them use the Gecko engine instead… Maybe that’s thé solution to many problems.

While I see the point that it is a deficiency on IE 6’s part, why can’t you use some variant of the old standard:

<a href=“#” onClick=“OpenLocation();return false;”>Google</a>

  • which does work on all browsers?

7stud, I’ve tried that all. None of it works, even with return false; and so on.

The js you posted with the html I posted works perfectly for me on windows IE6(with or without a DOCTYPE). However, you might me experiencing caching effects. In other words, if you load the page with the “javascript:” in there and see that the script doesn’t work, and then you change the html to what I posted and load the page again, IE may be caching the old page, so you aren’t seeing the effects of what happens when “javascript:” is removed.

By the way, using “javascript:” and inline event handlers in the html shouts out that whoever wrote the script is a beginner. So if you’re trying to impress clients with your javascript, that isn’t the way to do it.

A menuitem looks like this:

<a href=“javascript:;” onclick=“CommandName();”>MenuItem</a>

function CommandName()
  handler + '?filename=' + filename );

Note: here you DON’T need return false;

So you found one case where IE doesn’t choke on “javascript:”? Congratulations. If you think that’s justification to continue writing bad html and bad javascript, go right ahead.

This should work, IE doesn’t show any errors, or whatever.
As posted, no one will be able to make any sense out of that code. The following script works fine for me on windows IE6(with or without a DOCTYPE), although as I’ve suggested you shouldn’t write html and js like this:


<script type="text/javascript">

function CommandName()
	var activeFile = document.getElementById("[COLOR="Blue"]activeFile[/COLOR]");
	//activeFile is the file that is selected by right-clicking it
	var filename = activeFile.getAttribute('filename');
	//The code to handle the command, for example opening the filehandler
	var handler = activeFile.getAttribute('handler');
	if (handler == '' || handler == 'undefined') 
		alert('There is no program found to open this file.');
	else { handler + '?filename=' + filename );


<a href="javascript:" onclick="CommandName();">Menu</a>

<div id="[COLOR="Blue"]activeFile[/COLOR]" filename="file1" handler="[COLOR="Green"]blank2.htm"[/COLOR]>dummy</div>



<script type="text/javascript" >



<div>I am blank2.htm revised</div>


Another popular approach is:

function shiftOverOnce(){
  return false;


<a href="#" onclick="return shiftOverOnce();">shiftOverOnce</a>

You may wish to note that if you comment out:
//return false;

  • and watch IE 6’s location bar, you’ll see it briefly it go to the URL_encoded_whatever_filename_you_gave_it# location before loading this SitePoint page. That may help to explain its anomalous behaviour. It suggests the JScript interpreter is interrupting itself. MS products have been known to be a bit quarrelsome, even within themselves.

I’m not having a “who’s the most experienced”-contest, so stay to the point.
Read two books about javascript, one contradicts the other, in many ways.
What’s your hour rate? I’m willing to hire you for rewriting the javascript-code, bearing in mind that it will have to be expandable. And no, I’m not joking around here, I’m really willing to hire you for this.
I’m not trying to insult you here in any way, but people write code differently, and that’s just something you’ll have to accept.

It is difficult consideration when we don’t see whole code, mainly because not everyone here has good English. Could you send somewhere more complex example of described problem?

Found the error.
Works fine now, thanks for your replies though.

Grtz, Vince

Actually, what IE 6 is doing is not entirely indefensible. What is happening is the script is terminating before the browser has loaded the URL assigned to window.location.href and then, since return false isn’t specified, the browser is executing the link. Coming last, the link’s URL (or pseudo-URL) is what is ends up in window. The other browsers are suspending execution before activating the link, though I doubt that is any sort of codified standard.

Hi vince
Could you please provide the solution? Am getting similar errors and no solution for the problem.


Anyone looking for a solution to IE6 window.location failure:

var url = “newUrl.htm”;
setTimeout(function(){ window.location = url; }, 0);

IE6 doesn’t have a window.location failure if you code things properly.


I would like to have page which uses a few xhr objects
and automatically (after 30 seconds) starts the same few requests again

It works for me well in IE7, IE8, but not IE6 (where is in browsing history
chosen option “automatically” ). It works there only for first time and I can’t
set it for circular reloading. It looks like page is reloaded, but xhr objects are
not doing their job …only - as I wrote - for first time after page load.

I have tried a lot of things:

  • headers: no-caching
  • window.reload(true)
  • window.setInterval
  • window.location.assign

nothing helps

Any idea?


this is what i found:


works ok,

it was the href=” javascript:void(0);” which was preventing the onclick to work

Does not work:
<a onclick=“function()” href=" javascript:void(0);" >link</a>

Works ok:
<a onclick=“function()” href=“#” >link</a>