1

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. Its working on IE & Firefox. In the Chrome browser even an alert inside the window.onunload = function() will not get executed. How can I execute this one in Chrome. Is there any other way we can do it? (can't use the window.onbeforeunload = function() also)

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
mahesh chowdary
  • 432
  • 5
  • 13
  • 3
    It is JavaScript which is not Java! These two languages are totally different. – Bosko Mijin Jan 23 '14 at 09:50
  • Possible duplicate of: http://stackoverflow.com/questions/7794301/window-onunload-is-not-working-properly-in-chrome-browser-can-any-one-help-me You should find the answer there. – Paweł Piecyk Jan 23 '14 at 09:52

2 Answers2

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

If you want to use jQuery, this will work in all browsers.

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

That's because Chrome blocks alerts in the onunload event.

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>
Arun Raj
  • 243
  • 1
  • 7
  • 21
0

For onunload in all browser except opera by changing the asynchronous in to synchronous call request.

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

and its worked well for all browsers except Opera.

3bu1
  • 977
  • 12
  • 30
  • can you paste your code here so that i can explain you with your piece of code. – 3bu1 Jan 23 '14 at 10:02
  • window.onbeforeunload = beforeunload; window.onunload = function () { clearTimeout(showMsgTimer); retrieveURL("/janus/Logout.do?param=removeUserManagementLocksForController"); – mahesh chowdary Jan 23 '14 at 13:33