0

Hi All,

I want to run a HIDDEN FUNCTION when I click "OK"...not "CANCEL" in window.onbeforeunload() is it possible?

<script type="text/javascript">
window.onbeforeunload = function()
{
    var bUnsavedFields = true;

    if(bUnsavedFields)
    {
        window.event.returnValue = "I WANT THE OK BUTTON NOT CANCEL :) TO TRIGGER HIDDEN FUNCTION AFTER EXIT";
    }
    setTimeout("myFunction();",5000);
}

function myFunction(){
alert ("hello");
}
</script>
2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by twiss
0

I have a login system and I want the user if he exit the browser he will be automatically logout on his account.

0
window.onbeforeunload = function()
{
    return confirm('Do you want to leave this page?'); // or somethign like that
};
 
window.onunload = function()
{
    some_logout_stuff();
    something_else();
};

But, at a second thought, don't use this. If a user has two tabs with your application, and exits one of them, he/she is logged out. Instead, let sessions handle this for you.

Edited by twiss: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.