1

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  

    });
RealBadCoder
  • 351
  • 2
  • 5
  • 16
  • Try unload. https://api.jquery.com/unload/ – Khauri Jul 20 '17 at 22:07
  • 2
    `pagecontainerhide` http://api.jquerymobile.com/pagecontainer/#event-hide https://jqmtricks.wordpress.com/2014/03/26/jquery-mobile-page-events/ – Omar Jul 21 '17 at 04:27

1 Answers1

-1

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

Khauri
  • 3,753
  • 1
  • 11
  • 19