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

25 views
Skip to first unread message

Dr J R Stockton

unread,
Apr 15, 2007, 12:23:03 PM4/15/07
to
In comp.lang.javascript message <461ffd69$0$24719$4c36...@roadrunner.co
m>, Fri, 13 Apr 2007 18:00:09, Michael White <mi...@mickweb.com> posted:

>"document.location" is deprecated, use "document.URL" or
>"location.href" or "window.location.href"

A <FAQENTRY> on "Deprecated" might well be useful, though it would need
to be backed up by a Web page.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

stephen....@gmail.com

unread,
Apr 15, 2007, 3:30:09 PM4/15/07
to
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.

stephen....@gmail.com

unread,
Apr 13, 2007, 4:21:04 PM4/13/07
to
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?

Michael White

unread,
Apr 13, 2007, 6:00:09 PM4/13/07
to
stephen....@gmail.com wrote:

"document.location" is deprecated, use "document.URL" or "location.href"
or "window.location.href"

Mick

Reply all
Reply to author
Forward
0 new messages