Set/Navigate to a Location (what is the correct way?)

S

stephen.cunliffe

Hi all,

This may sound real strange, but I'm curious what the "official"
answer is.

In my JS, I want to redirect/navigate to a url...

In Mozilla,

document.location.href = '{my_url}'; //works in Moz, IE6, IE7, Opera,
etc.

window.location.href = '{my_url}'; //works in Moz, IE6, IE7, Opera,
etc.

But.... there are times, in IE6, when...

document.location.href = '{my_url}';

does *NOT* work... and IE just ignores the request...

Now, from all the specs I read, it looks like location.href was only
ever intended to be read-only... but browsers seemed to make it
editable... and in IE6, document.location.href( '{my_url}' ); even
works (sometimes), because MS added this ability because so many were
trying it, finding it not to work, and submitting bugs...


So, 2 questions...

1.) What is the "official" way to set the page location (e.g. to some
other page)
2.) If document.location.href is fine, anyone know why IE sometimes
ignores it, when it is set to a new value?
 
S

stephen.cunliffe

I'm not sure what happened to the begining of this thread, but I
figured out what was happening.

In IE6 only, if you have a link (change square brackets for angled)

[a href="javascript:;" onclick="doSomething"]Click Me[/a]

and...

[script]
function doSomething(){
document.location.href = 'http://www.example.com/';
}
[/script]


It won't work.. well, kind of. It actually does the HTTP GET request,
on "example.com", but the original page never leaves the screen, the
"flag" in the corner doesn't wave, and the progress bar only flashes
for a few milliseconds. As far as the user sees it, nothing happened.
(even the history of visiting this link is not stored)

Its like 1/2 AJAX in IE6, without the ActiveX, and without the
postback.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top