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

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

  1. 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,

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

    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?
    stephen.cunliffe, Apr 13, 2007
    1. Advertisements

  2. In comp.lang.javascript message <461ffd69$0$24719$
    A <FAQENTRY> on "Deprecated" might well be useful, though it would need
    to be backed up by a Web page.
    Dr J R Stockton, Apr 15, 2007
    1. Advertisements

  3. 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]


    function doSomething(){
    document.location.href = '';

    It won't work.. well, kind of. It actually does the HTTP GET request,
    on "", 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
    stephen.cunliffe, Apr 15, 2007
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.