windows.location.href not working on Firefox3

前端 未结 17 1160
囚心锁ツ
囚心锁ツ 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: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

提交回复
热议问题