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

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

问题描述

我的问题是有点棘手。至少我觉得。也许不是,反正。我想知道如果有任何办法知道,如果用户离开页面。无论他是否点击previous按钮,关闭窗口或ckicking在我的网站的链接。如果我的记忆仍然是不错的,我认为这是可能用JavaScript。

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.

但在我而言,我想在我的codebehind做一些东西(清洗对象)。

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.

您可以用JavaScript做到这一点,但它是非常困难的。

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

查看<一个href=\"http://stackoverflow.com/questions/821011/how-do-you-$p$pvent-javascript-page-from-navigating-away\">question这里。

本脚本也可以工作。结果发现这里

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天全站免登陆