Jquery:window.unload不能使用chrome 72.0.3626.109 [英] Jquery: window.unload not working with chrome 72.0.3626.109
本文介绍了Jquery:window.unload不能使用chrome 72.0.3626.109的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 asp.net mvc
创建一个网络应用程序。我想检测用户的手动刷新,
I am creating a web app using asp.net mvc
. I want to detect a manual refresh by a user,
但是我无法获得以下事件
but I am not able to get the following events
1:beforeunload
1: beforeunload
2:卸载
以下我试过的方式
1
1
$(window).on('beforeunload', function () {
pageCleanup();
});
2
2
$(window).on("unload", function () {
pageCleanup();
});
function pageCleanup() {
alert(1)
}
3
3
window.addEventListener("unload", logData);
function logData() {
alert(1)
}
4
4
$(window).unload(function () {
alert('1');
});
上面是一个带警报的例子,我想要一个ajax调用
卸载函数
the above is an example with alert, I want to have an ajax call in unload function
但是当用户按下任何类型的刷新时,这些似乎都没有执行(F5,ctrl -shift-R,ctrl-R,来自网址标签)
but none of these seems to execute when a user press any kind of refresh(F5, ctrl-shift-R, ctrl-R, from url tab)
我现在该怎么办?
推荐答案
嗨检查一次让我知道
<html>
<head>
<title>Refresh a page in jQuery</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
</head>
<body>
<h1>Stop a page from exit with jQuery</h1>
<button id="reload">Refresh a Page in jQuery</button>
<script type="text/javascript">
$('#reload').click(function() {
location.reload();
});
$(window).bind('beforeunload', function(){
return '>>>>>Before You Go<<<<<<<< \n bro!!Working';
});
</script>
</body>
</html>
这篇关于Jquery:window.unload不能使用chrome 72.0.3626.109的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文