使用jquery重定向刷新

时间:2016-08-25 17:37:14

标签: javascript php jquery

我正在尝试检测用户何时刷新页面以使用JQuery重定向,这段代码有什么问题? 但我没有尝试任何工作

<?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>

1 个答案:

答案 0 :(得分:0)

您的代码运行正常。 Chrome正在阻止警报。

注意 console.log 如何运行没有任何问题。

这是我测试的代码:

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

这是输出:

enter image description here