3

I need to catch closing tab/browser on mobile. onunload & onbeforeunload javascript event can catch refresh page, submit form, redirect page, close tab/browser... It worked perfectly on PC, but when I tried these events on mobile browsers (Chrome on Android, Safari on iOs). It can not catch closing tab/browser event. Please see my code below:

 <script>   
    window.onunload = window.onbeforeunload = function (e) {
        var e = e || window.event;

        // For IE and Firefox prior to version 4
        if (e) {        
            //window.open("http://www.w3schools.com");
            return "Hello";
        }

        // For Safari   
        //window.open("http://www.w3schools.com/jsref/event_onunload.asp");
        return "Hello";
    };  
  </script>
  <?php echo "Test onunload and onbeforeunload event"; ?>

Could you please advise?

Thanks

Gwenc37
  • 2,064
  • 7
  • 18
  • 22
Ryan Adolf
  • 31
  • 4

0 Answers0