通过body/window卸载事件调用时location.href在chrome中不起作用 [英] location.href does not work in chrome when called through the body/window unload event

查看:433
本文介绍了通过body/window卸载事件调用时location.href在chrome中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Javascript-从window/body卸载事件调用时,document.location或window.location或window.location.href或location.href在Google Chrome 6和7(我没有测试过较低版本)中不起作用.两种方法似乎都可以在IE,Firefox和Safari浏览器上正常工作.

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.

通过更多的测试,通过单击事件或其他任何事件,我能够看到此重定向实际上在chrome中有效.但是,在正文 unload 事件中调用此方法时.它不起作用.

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.

示例代码:

<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>

我仍在努力寻找一种在Chrome中运行该方法的方法.任何帮助将不胜感激.

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

谢谢, 尼维德(Nived)

Thanks, Nived

推荐答案

尝试一下

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

这篇关于通过body/window卸载事件调用时location.href在chrome中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆