Я создаю веб-приложение, используя asp.net mvc. Я хочу обнаружить ручное обновление пользователем,
но я не могу получить следующие события
1: beforeunload
2: unload
следующим образом я пытался
1
$(window).on('beforeunload', function () {
pageCleanup();
});
2
$(window).on("unload", function () {
pageCleanup();
});
function pageCleanup() {
alert(1)
}
3
window.addEventListener("unload", logData);
function logData() {
alert(1)
}
4
$(window).unload(function () {
alert('1');
});
the above is an example with alert, I want to have an ajax call in unload function
но ни один из них, похоже, не выполняется, когда пользователь нажимает какое-либо обновление (F5, ctrl-shift-R, ctrl-R, с вкладки URL)
что мне теперь попробовать?



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Привет, проверь один раз и дай мне знать
<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>
Вы должны использовать bind вместо beforeunload:
$(window).bind("beforeunload", () => alert(1));<script src = "https://code.jquery.com/jquery-3.3.1.js"></script>