Take the 2-minute tour ×

I want to inform my server that a user has closed browser tab/window with our app.

I found out that running an ajax call with async:false binded to a window.beforeunload evet will work and it does. Sort of...

window.onbeforeunload = beforeunload;

function beforeunload() 
    setSendingPowerStatus(false, true);


So, in chrome user closes the window and setSendingPowerStatus(false, true); function which in its implementation makes a synchronous call is being executed and when done browser closes the tab. In FF, on the other hand, user is prompted with that alert dialog asking "Are U sure you wanna leave the page?".

My question is how to execute ajax call on onbeforeunload event without showing any dialog??? I mean I want to execute an ajax call before window is closed without bothering the user...

I also tried to return false also from my handler function, but without luck there either...

share|improve this question

1 Answer 1

I suggest you retry like that(setting returnValue to true, and returning true) :

function beforeunload(event) 
    setSendingPowerStatus(false, true);
    return true;
window.onbeforeunload = beforeunload;
share|improve this answer

Your Answer


