-2
window.onbeforeunload = logout;
function logout()
  {
     window.location.href = "logout URL";
     }

How can we write asynch method for this code? Only by using setTimeout or any other?

Thanks in Advance

  • 1
    What is it that you want to achieve? – Daniel Sep 17 '13 at 07:09
  • onbeforeunload methods you are using are unsupported most browsers. what is your requirement ? what by mean asyn? – internals-in Sep 17 '13 at 07:10
  • @ 7-isnotbad, what command or method we can use instead of onbeforeunload to wrok in all browsers? – user2632735 Sep 17 '13 at 07:14
  • 1
    @7-isnotbad: `onbeforeunload` seems to have good enough browser support: https://developer.mozilla.org/en-US/docs/Web/API/window.onbeforeunload#Browser_compatibility. – Felix Kling Sep 17 '13 at 07:18
  • @FelixKling including older version off all brwsrs? thought of No ! – internals-in Sep 17 '13 at 07:24
  • 1
    @7-isnotbad: Did you follow the link? It's supported in Chrome 1, FF 1, IE 4 and Safari 3. I think that would cover 99% of all Internet users. Apparently it's only supported in Opera 15, but I would assume that those who use Opera also use the latest version. – Felix Kling Sep 17 '13 at 07:28
  • @FelixKling oh Sorry tracked at olden comments http://stackoverflow.com/questions/14645011/window-onbeforeunload-and-window-onunload-is-not-working-in-firefox-safari-o – internals-in Sep 17 '13 at 07:31

1 Answers1

0

As i understand

onbeforeunload is supported by most browsers. Even opera in the newever versions.

If you want to catch the event

Source: Crossbrowser onbeforeunload?

window.onbeforeunload = function (e) {
    var e = e || window.event;

    // For IE and Firefox
    if (e) {
        e.returnValue = '';
    }

    // For Chrome and Safari
    return '';
};

Extra:

Is there any way to make onbeforeunload work in Opera?

Alternatives to window.onbeforeunload for sending data?

Community
  • 1
  • 1
Daniel
  • 2,002
  • 5
  • 20
  • 32
  • Hi, I can capture the event and say the message to close the browser or not. But i want to logout the user session in my server. I need to redirect user to logout page sothat user session will be terminated in my server. And this should work in all browsers. when is use window.location.href it is not working for Chrome. I need a command to reidrect user to logout page when user clicks X button of any browser. – user2632735 Sep 17 '13 at 07:58