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

Discussion in 'Javascript' started by stephen.cunliffe@gmail.com, Apr 13, 2007.

  1. Guest

    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?
    , Apr 13, 2007
    #1
    1. Advertising

  2. In comp.lang.javascript message <461ffd69$0$24719$
    m>, Fri, 13 Apr 2007 18:00:09, Michael White <> 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)
    Dr J R Stockton, Apr 15, 2007
    #2
    1. Advertising

  3. Guest

    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.




    On Apr 15, 12:23 pm, Dr J R Stockton <> wrote:
    > In comp.lang.javascript message <461ffd69$0$24719$
    > m>, Fri, 13 Apr 2007 18:00:09, Michael White <> 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)
    , Apr 15, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TGluZGEgV2llbmhvbHQ=?=

    Navigate to specific location on page

    =?Utf-8?B?TGluZGEgV2llbmhvbHQ=?=, Mar 1, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    387
    Rajiv R
    Mar 1, 2004
  2. joon
    Replies:
    1
    Views:
    509
    Roedy Green
    Jul 8, 2003
  3. Ed Sutton
    Replies:
    1
    Views:
    425
    Cowboy \(Gregory A. Beamer\)
    Sep 15, 2006
  4. =?Utf-8?B?UmljaGFyZA==?=

    Differences/best way to navigate thru pages

    =?Utf-8?B?UmljaGFyZA==?=, Jun 27, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    442
    =?Utf-8?B?UmljaGFyZA==?=
    Jun 28, 2007
  5. Fren Zeee
    Replies:
    4
    Views:
    646
    Emmy Noether
    Aug 5, 2010
Loading...

Share This Page