有没有办法知道用户离开页面与asp.net? [英] Is there any way to know that user leaving a page with asp.net?
问题描述
但在我的情况下,我想在我的代码中做一些东西(清洁对象)。
真的没办法。
您可以使用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屋!