【发布时间】:2012-12-14 10:00:40
【问题描述】:
我需要知道是否有可能捕获用户关闭浏览器窗口。我试过使用<body onbeforeunload="run_closeScripts()">,它工作得很好,但这会在每次回发时触发!因此,如果用户点击刷新按钮或转到另一个页面,它没有多大用处。
是否有可靠的方法来检测它是否关闭了完整的浏览器而不是回发?
<body onbeforeunload="run_closeScripts()">
<script type="text/javascript">
function run_closeScripts() {
//check if the browser is closing and not a postback
window.alert("Your checkout will be removed!");
window.location.replace("Exit.aspx");
}
【问题讨论】:
-
不,实际上不是。可能有一些事件可能会被捕获,但不是全部
-
您问题的标签表明您正在使用的平台,因此它们不需要在您的标题中重复。
标签: c# javascript asp.net session browser