I need to execute a function when the user leaves the page. This is my code on pageinit. How could I do the same when leaving?
$("#page2").on("pageinit", function (myEvent) {
//Things to do
});
I need to execute a function when the user leaves the page. This is my code on pageinit. How could I do the same when leaving?
$("#page2").on("pageinit", function (myEvent) {
//Things to do
});
You could use jQuery's unload event,
https://api.jquery.com/unload/
But it's probably better to use the vanilla javascript beforeunload event as it's probably faster.
https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload