当我单击MenuItem打开一个新的aspx页面时,我有一个带有MasterPage和内容页面的ASP.NET Web应用程序.如果我想关闭新的页面浏览器选项卡,我想显示一个弹出窗口或一个对话框,提醒用户他正在关闭浏览器选项卡.我不知道如何检测关闭browserTab按钮.
我在新的aspx页面中使用了以下代码:
我在新的aspx页面中使用了以下代码:
<script type="text/javascript"> function CloseWindow() { alert('closing'); window.close(); } </script>
protected void Page_Load(object sender,EventArgs e) { Page.ClientScript.RegisterOnSubmitStatement(typeof(Page),"closePage","window.onunload = CloseWindow();"); }
Thanx在优势.
@R_404_323@
这很完美.
javascript detect browser close tab/close browser
<body onbeforeunload="ConfirmClose()" onunload="HandleOnClose()"> var myclose = false; function ConfirmClose() { if (event.clientY < 0) { event.returnValue = 'You have closed the browser. Do you want to logout from your application?'; setTimeout('myclose=false',10); myclose=true; } } function HandleOnClose() { if (myclose==true) { //the url of your logout page which invalidate session on logout location.replace('/contextpath/j_spring_security_logout') ; } }