Javascript无法在chrome卸载事件上运行?

时间:2017-04-23 22:16:59

标签: javascript google-chrome

我想要在联系页面上运行一些简单的javascript,它应该在页面加载时显示弹出窗口,并在用户导航时显示不同的弹出窗口。

我在下面的代码在IE上工作正常但在chrome上onunload部分根本不起作用。

这有什么解决方法吗?

 <script>
          window.onload = function(){
              alert('Even if you aren\'t interested, please give our design some feedback as we would like to stay current.');
              return;
          }
          window.onunload = function(){
              alert('Thank you for your time and consideration');
              return;
          }
    </script>

1 个答案:

答案 0 :(得分:0)

尝试:

window.onload = function(){
          alert('Even if you aren\'t interested, please give our design some feedback as we would like to stay current.');
          return;
      }
      window.beforeunload = function(){
          alert('Thank you for your time and consideration');
          return;
      }