Answer the question
In order to leave comments, you need to log in
How to catch page refresh (reload) event?
There are 2 tabs.
When one is closed, by the onunload event, it transfers data to another.
But there's a problem. onunload also works on page reloads.
The question arose, how to catch the reboot event? Through keydown and the key code will not work, because the user can also click on the page reload button in the browser.
Answer the question
In order to leave comments, you need to log in
There is no such event. And I personally do not see a solution to the problem, as it is posed.
But you probably don't need to pass data on close. It may be suitable to synchronize data between open tabs of your domain.
Look here https://habr.com/ru/company/rambler_and_co/blog/422545/
document.addEventListener("DOMContentLoaded", function(){
//if IsRefresh cookie exists
var IsRefresh = getCookie("IsRefresh");
if (IsRefresh != null && IsRefresh != "") {
//cookie exists then you refreshed this page(F5, reload button or right click and reload)
//SOME CODE
DeleteCookie("IsRefresh");
}
else {
//cookie doesnt exists then you landed on this page
//SOME CODE
setCookie("IsRefresh", "true", 1);
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question