有没有办法知道用户离开页面与asp.net? [英] Is there any way to know that user leaving a page with asp.net?

查看:134
本文介绍了有没有办法知道用户离开页面与asp.net?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题有点棘手。至少我想。也许不是,反正。我想知道是否有任何方式知道用户是否离开页面。无论他点击上一个按钮,关闭窗口或ckicking在我的网站上的一个链接。如果我的记忆力仍然很好,我认为这是可能的。



但在我的情况下,我想在我的代码中做一些东西(清洁对象)。

解决方案

真的没办法。



您可以使用Javascript进行操作,但最好是很难。



请参阅这里的问题



此脚本也可以正常工作。发现此处

 < script> 

window.onbeforeunload = function(evt){
var message ='你确定要离开吗?
if(typeof evt =='undefined'){
evt = window.event;
}
if(evt){
evt.returnValue = message;
}
返回消息;
}

< / script>


My question is a little bit tricky. at least I think. Maybe not, anyway. I want to know if there's any way to know if the user is leaving the page. Whatever if he clicks "Previous button", closing the window or ckicking on a link on my website. If my memory's still good, I think it's possible with JavaScript.

But in my case, I want to do some stuff (cleaning objects) in my codebehind.

解决方案

There really is no way to do it. No event is fired when the browser goes back.

You can do it with Javascript, but it is difficult at best.

See the question here.

This script will also work. It was found here

<script>

window.onbeforeunload = function (evt) {
var message = ‘Are you sure you want to leave?’;
if (typeof evt == ‘undefined’) {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}

</script> 

这篇关于有没有办法知道用户离开页面与asp.net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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