相关疑难解决方法(0)

如何捕获浏览器窗口关闭事件?

我想捕获浏览器窗口/选项卡关闭事件.我用jQuery尝试了以下内容:

jQuery(window).bind(
    "beforeunload", 
    function() { 
        return confirm("Do you really want to close?") 
    }
)
Run Code Online (Sandbox Code Playgroud)

但它也适用于表单提交,这不是我想要的.我想要一个仅在用户关闭窗口时触发的事件.

javascript browser jquery events

142
推荐指数
5
解决办法
37万
查看次数

如何防止关闭浏览器窗口?

我尝试使用以下代码在关闭浏览器窗口时收到警报:

window.onbeforeunload = confirmExit;
function confirmExit() {
  return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Save button, your changes will be lost.  Are you sure you want to exit this page?";
}
Run Code Online (Sandbox Code Playgroud)

它有效,但如果页面包含一个超链接,则单击该超链接会引发相同的警报.我只有在关闭浏览器窗口而不是单击超链接时才需要显示警报.

javascript browser window onbeforeunload

53
推荐指数
3
解决办法
8万
查看次数

Javascript窗口关闭事件而不是所有浏览器的卸载事件

我想在用户尝试关闭浏览器而没有保存某些设置时提醒用户.

我在另一个页面中卸载选项以提醒卸载数据,但是如何在window.close上警告用户(它没有采取)

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";
    }
}
Run Code Online (Sandbox Code Playgroud)

我想在所有浏览器中关闭选项卡和窗口关闭window.close.

请找我一个解决方案

javascript

10
推荐指数
2
解决办法
4万
查看次数

标签 统计

javascript ×3

browser ×2

events ×1

jquery ×1

onbeforeunload ×1

window ×1