-1

I'm trying to detect when the user refresh the page to redirect using JQuery ,what is wrong in this code? but nothing that I try works

<?php
  include 'instagram.php';
 ?>
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>

  <body>
    <?php
      $inst = new Instagram($_GET['code']);
     ?>

     <script
              src="https://code.jquery.com/jquery-2.2.4.min.js"
              integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
              crossorigin="anonymous">
    </script>
    <script>
      $(window).bind('beforeunload', function(){
            alert("tryng to refresh");
        });
    </script>
  </body>

</html>
AFS
  • 1,433
  • 6
  • 28
  • 52

1 Answers1

0

Your code works fine. Chrome is blocking the alert.

Notice how the console.log runs with no problems.

This is the code I tested:

$(window).bind('beforeunload', function(){
  alert("tryng to refresh");
  console.log('leaving page');
  return '';
});

Here is the output:

enter image description here

hcontreras
  • 300
  • 2
  • 11