ASP.NET如何捕捉到用户关闭浏览器 我想在用户关闭浏览器的时候执行一段代码求解决方案 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 运用onunload事件判断浏览器是刷新还是关闭窗口 this.onunload=function (event) { if(event.clientX<=0 && event.clientY<0) { alert("关闭了浏览器!"); } } 这个如果是在任务拦有右键菜单管理的好象没办法捕获的. <script language="javascript">window.onunload=function(){ alert('关了啊');}</script> onunload是可以。。但不准确。。如果当关闭后要执行什么。。还是通过判断这个用户N时间内没有活动。。视为关闭好点 onunload在刷新的时候也会触发,所以无法判定是刷新还是关闭 这个刷新不触发你想执行的的事。<script type="text/javascript"> function window.onbeforeunload() { if (event.clientX > 360 && event.clientY < 0 || (event.altKey)) { window.onbeforeunload = null; //做你想处理的事 }}</script> javascript还有一点希望.asp.net是打酱油的 用时间判断。没有捷径的。IIS 也是这么判断的。 你关闭后要做什么啊?是不是想清空session等的东西啊?要是这样的话 我通常用法是:在登录之前 清空session <script language="javascript"> function closewin() { if(confirm("你确定要关闭窗口吗?")) window.close(); else alert("窗口未关闭"); }</script></head><body><input type="button" value="关闭窗口" onclick="closewin()" /></body>IE中成功关闭窗口,firefox中未来成功 ASP.NET中<head runat="server"> <title>无标题页</title> <script language="javascript"> function closewin() { if(confirm("你确定要关闭窗口吗?")) window.close(); else alert("窗口未关闭"); } </script></head><body> <form id="form1" runat="server"> <div> <asp:Button ID="btn1" OnClientClick="closewin()" runat="server" /></div> </form></body>IE验证成功!主要就是为asp按钮加上一个属性OnClientClick:表示用客户端的JavaScript脚本来响应用户的单击事件;至于其他的代码你自己也可以加上去 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>onbeforeunload测试</title> <script> function checkLeave(){ event.returnValue="确定离开当前页面吗?"; } </script> </head> <body onbeforeunload="checkLeave()"> </body> </html> 哎~~你都这么多年了 我都是个初学者怎么想得到好办法啊比较好的就是用onbeforeunload() 和 时间判断 XML:如何通过属性获取节点-不论tagName SQL更新最新一条数据怎么写? 急、急、急!!!!!!!! 可以访问静态页面,无法访问动态页面 如何在winform里面显示 owc画出的图片 请问怎样把货币型的0.01显示为0.01而不是.01 这种统计是怎么做的? 如何将自己的项目发布到外网上? 求教,在aspx.cs页面,this.控件ID 不识别 WCF MEX终结点 发布元数据问题。 win7和XP的系统时间不相同,请问如何解决? 关于截取字符的简单问题?
this.onunload=function (event) {
if(event.clientX<=0 && event.clientY<0) {
alert("关闭了浏览器!");
}
}
这个如果是在任务拦有右键菜单管理的好象没办法捕获的.
window.onunload=function()
{
alert('关了啊');
}
</script>
在刷新的时候也会触发,所以无法判定是刷新还是关闭
function window.onbeforeunload() {
if (event.clientX > 360 && event.clientY < 0 || (event.altKey)) {
window.onbeforeunload = null;
//做你想处理的事
}
}
</script>
asp.net是打酱油的
<script language="javascript">
function closewin()
{
if(confirm("你确定要关闭窗口吗?"))
window.close();
else
alert("窗口未关闭");
}
</script>
</head><body>
<input type="button" value="关闭窗口" onclick="closewin()" />
</body>IE中成功关闭窗口,firefox中未来成功
<title>无标题页</title>
<script language="javascript">
function closewin()
{
if(confirm("你确定要关闭窗口吗?"))
window.close();
else
alert("窗口未关闭");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btn1" OnClientClick="closewin()" runat="server" /></div>
</form>
</body>IE验证成功!
主要就是为asp按钮加上一个属性OnClientClick:表示用客户端的JavaScript脚本来响应用户的单击事件;
至于其他的代码你自己也可以加上去
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>onbeforeunload测试</title>
<script>
function checkLeave(){
event.returnValue="确定离开当前页面吗?";
}
</script>
</head>
<body onbeforeunload="checkLeave()">
</body>
</html>
哎~~你都这么多年了 我都是个初学者怎么想得到好办法啊比较好的就是用onbeforeunload() 和 时间判断