windows.location.href not working on Firefox3

前端 未结 17 1095
囚心锁ツ
囚心锁ツ 2020-11-30 07:31

We have a JavaScript function named \"move\" which does just \"windows.location.href = any given anchor\".
This function works on IE, Opera and Safari, but so

相关标签:
17条回答
  • 2020-11-30 08:18

    Have you tried this?

    Response.Write("<script type='text/javaScript'> window.location = '#myAnchor'; </script>";); 
    
    0 讨论(0)
  • 2020-11-30 08:19

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

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

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

    Update I got it working! with a

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

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

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

    0 讨论(0)
  • 2020-11-30 08:27

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

    function thisWorks()
    {
        window.location.href = "http://www.google.com";
        return false;
    }
    
    function thisDoesNotWork()
    {
        window.location.href = "http://www.google.com";
    }
    
    0 讨论(0)
  • 2020-11-30 08:31

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

    0 讨论(0)
  • 2020-11-30 08:32

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

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

    0 讨论(0)
提交回复
热议问题