[ACCEPTED]-windows.location.href not working on Firefox3-firefox

Accepted answer
Score: 36

Have you tried just using

window.location = 'url';

In some browsers, window.location.href is 7 a read-only property and is not the best 6 way to set the location (even though technically 5 it should allow you to). If you use the 4 location property on its own, that should redirect 3 for you in all browsers.

Mozilla's documentation 2 has a pretty detailed explanation of how 1 to use the window.location object.

https://developer.mozilla.org/en/DOM/window.location

Score: 19

If you are trying to call this javascript 11 code after an event that is followed by 10 a callback then you must add another line 9 to your function:

function JSNavSomewhere()
{
    window.location.href = myUrl;
    return false;
}

in your markup for the 8 page, the control that calls this function 7 on click must return this function's value

<asp:button ........ onclick="return JSNavSomewhere();" />

The 6 false return value will cancel the callback 5 and the redirection will now work. Why 4 this works in IE? Well I guess they were 3 thinking differently on the issue when they 2 prioritized the redirection over the callback.

Hope 1 this helps!

Score: 5

One observation to ensure in such a scenario

Following 3 will work in IE, but neither in Chrome nor in Firefox (the 2 versions I tested)

 window.location.href("http://stackoverflow.com");

Following will work all 1 the three

window.location.href = "http://stackoverflow.com";
Score: 4

Maybe it's just a typo in your post and 1 not in your code, but it's window and not windows

Score: 2

I am not sure to follow you.
I just tried: going 6 with FF3 to Lua 5.1 Reference Manual (long and with lot of anchors).
Pasting 5 javascript:window.location.href="#2.5"; alert(window.location.href); in the address bar, I went to the right 4 anchor and it displayed the right URL. Works 3 also with a full URL, of course.
Alternative 2 code: javascript:(function () { window.location.href="#2.5"; })();

Perhaps you forgot the #. Common problem, also 1 with image maps.

Score: 2

I have the same problem and I guess this 15 is related to a click event.

I have a function that 14 moves the browser to a specific page. I 13 attach that function to some click events: in 12 a button and in a image. AlsoI execute the 11 function when the user press escape (document 10 onkeypress event).

The results are that in 9 all cases the function is called and executed, but 8 only when there is a click the browser goes 7 to the address I want.

Update I got it working! with 6 a

setTimeout( "location.replace('whatever.html');", 0 );

I don't know why the location.replace 5 wasn't working when the event was a keypress, but 4 with the settimeout it works :)

Update Returning 3 false after the event when you press escape 2 makes the redirection works. If you return 1 true or nothing the browser will not follow

Score: 2

You've got to add return false; after the window.location.href 1 as mentioned above.

function thisWorks()
{
    window.location.href = "http://www.google.com";
    return false;
}

function thisDoesNotWork()
{
    window.location.href = "http://www.google.com";
}
Score: 1

window.location.href works fine in all versions 5 of Firefox, as does document.location.href 4 I think that there is something else in 3 your code that is breaking things.

drop this 2 in a blank page, if it works, it indicates 1 there is something else wrong on your page.

<script>
  window.location.href = 'http://www.google.com/';
</script>
Score: 1

sometime if you're using form to post data, this 4 may happen. if you're using ajax, try to 3 change 'form' to 'div'. this will prevent 2 the default behavior of form and do your 1 ajax code.

Score: 0

You could also use window.location.replace to jump to an anchor 3 without register it in the browser history:

This 2 article illustrates how to jump to an anchor and 1 uses href as read-only property.

function navigateNext() 
{
    if (!window.location.hash) 
    {
        window.location.replace(window.location.href + unescape("#2"))
    } 
    else 
    {
        newItem = nextItem(window.location.hash)
        if (document.getElementById(newItem)) 
        {
            window.location.replace(stripHash(window.location) + "#" + newItem)
        } 
        else 
        {
            window.location.replace(stripHash(window.location) + "#1")
        }
    }
}
Score: 0

Have you tried this?

Response.Write("<script type='text/javaScript'> window.location = '#myAnchor'; </script>";); 

0

Score: 0
window.location.hash = "#gallery";

0

Score: 0

please add full javascript script tag

<script type="text/javascript" language="javascript"></script>

0

Score: 0

For reference I had the same problem.

onclick 4 = "javascript: window.location('example.html');" didn't 3 work under FF (latest)

I just had to rewrite 2 to onclick = "javascript: window.location 1 = 'example.html';" to get it working

Score: 0

I just overcome the same problem. and the 4 problem is not in javascript, but the href 3 attribute on the <a> element.

my js code

function sebelum_hapus()
{
var setuju = confirm ("Anda akan menghapus data...")
if (setuju)
window.location = "index.php";
}

my previous 2 html was

<a href="" onClick="sebelum_hapus();">Klik here</a>

and I update it to

<a href="#" onClick="sebelum_hapus();">Klik here</a>

or remove the 1 href attribute

hope this helps.

Score: 0

window.location.assign("link to next page") should 1 work in both (chrome and firefox) browsers.

window.location.assign("link to next page")

More Related questions