location.href does not work in chrome when called through the body/window unload event

☆樱花仙子☆ 提交于 2019-12-11 02:05:55

问题


Javascript - document.location or window.location or window.location.href or location.href does not work in Google Chrome 6 and 7(i didnt test lowers versions) when called from the window/body unload event. Both the ways seems to work fine with IE, Firefox and Safari browsers.

Through more testing i was able to see that this redirect actually works in chrome when done through a click event or any other. However when this is called in the body unload event. it does not work.

Sample Code:

<html>
    <script type="text/javascript">
        function check()
        {
            location.href="http://www.google.com";
        }
    </script>

    <body onunload="check()">

        <input type="button" onclick="check();" value="check">

    </body>
</html>

I am still trying to find a way to have this working in Chrome... Any help would be greatly appreciated.

Thanks, Nived


回答1:


try this out

setTimeout(function(){
    document.location.href = "page.html;"},500);


来源:https://stackoverflow.com/questions/6955734/location-href-does-not-work-in-chrome-when-called-through-the-body-window-unload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!