简体   繁体   English

里面的onunload <body> 在Google Chrome上无法使用

[英]onunload inside <body> does not work on Google Chrome

Browser compatibility please give me answer...... 浏览器兼容性,请给我答案...

window.onbeforeunload = beforeunload;
window.onunload = function() {
    clearTimeout(showMsgTimer);
    retrieveURL("/janus/Logout.do?param=removeUserManagementLocksForController");

But its not working inside the chrome browser only. 但是它不能仅在chrome浏览器中运行。 Its working on IE & Firefox. 它可以在IE和Firefox上运行。 In the Chrome browser even an alert inside the window.onunload = function() will not get executed. 在Chrome浏览器中,即使window.onunload = function()内的警报也不会执行。 How can I execute this one in Chrome. 如何在Chrome中执行此操作。 Is there any other way we can do it? 我们还有其他方法可以做到吗? (can't use the window.onbeforeunload = function() also) (也不能使用window.onbeforeunload = function()

      window.onunload = function(){
      alert("Are you sure?");
      }

If you want to use jQuery, this will work in all browsers. 如果要使用jQuery,它将在所有浏览器中都适用。

      $(window).unload(function () {
      alert("Are you sure?");
      });

That's because Chrome blocks alerts in the onunload event. 这是因为Chrome浏览器会在onunload事件中阻止警报。

Window.onbeforeunload Window.onbeforeunload

Note that it use 'return' to prompt message before closing the page. 请注意,在关闭页面之前,它使用“返回”来提示消息。

      <script type="text/javascript">
      window.onbeforeunload = Call;
      function Call() {
        //alert("Unload Called");
        return "You are going to close this window?";
      }
      </script>

For onunload in all browser except opera by changing the asynchronous in to synchronous call request. 通过将异步输入更改为同步调用请求,以便在除Opera之外的所有浏览器中进行onunload。

xmlhttp.open("POST","LogoutAction",false);

and its worked well for all browsers except Opera. 它对Opera以外的所有浏览器都适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM