Javascript窗口关闭事件而不是所有浏览器的卸载事件 [英] Javascript window close event rather than unload event for all browsers

查看:125
本文介绍了Javascript窗口关闭事件而不是所有浏览器的卸载事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在用户尝试关闭浏览器而不保存某些设置时提醒用户。

I want to alert a user while the user tries to close the browser with out siginingoff or without saving some settings.

我在另一个页面中将ding卸载选项警告卸载数据,但我如何在window.close上警告用户(它没有服用)

I am ding unload option in another page to alert unload data, but how can i alert a user on window.close(its not taking)

window.onbeforeunload = confirmExit;
function confirmExit(){
    if(readCookie("onlineVD") == "playing" && Confirm_Delete=="0")
    {
        return "You are leaving a video which is in play mode.Are you sure want to exit this page?";
    }
    else{
        Confirm_Delete="0";
    }
}

我想要关闭和关闭标签上的window.close窗口关闭所有浏览器。

I want window.close for on tab close and on window close in all browsers.

请找我解决方案

推荐答案

我测试时,您似乎已经使用了事件代码。您只需返回false即可阻止浏览器关闭。系统会询问用户是否确定要离开该页面。

The event code you have already seems to work when I test it. You just need to return false to stop the browser from closing. The user will be asked if they're sure they want to navigate away from the page.

我正在使用此缩短版的代码:

I'm using this shortened version of your code:

window.onbeforeunload = confirmExit;
function confirmExit(){
    alert("confirm exit is being called");
    return false;
}

这篇关于Javascript窗口关闭事件而不是所有浏览器的卸载事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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