Possible Duplicate:
How do I stop a page from unloading (navigating away) in JS?
I've created an online whiteboard. I wish to confirm from user whether he wants to leave the page or not (since he needs to save whiteboards before leaving)
$(window).bind('beforeunload', function(){
return 'Are you sure you want to leave?';
});
Now I need to call a function if the user confirms to leave the page. That function will post to the DB from jQuery (which I know how to do) & convert the user from active to inactive.
Only trouble I'm having is how do i get that function to be executed when the user CONFIRMS to leave.
Thanks!
FURTHER...
$(window).bind('beforeunload', function(){
return 'Are you sure you want to leave?';
});
window.onunload=pageleave();
function pageleave() {
var grp=$("#grpid").val();
var login=$("#loginid").val();
$.ajax({
type: 'POST',
url:'collwb_pageleave.php',
data: { GrpID:grp, LogID:login },
cache:false,
});
}
Here what happens is, on page load, pageleave gets executes and make Activity=0 in the Database. This should happen on page unload... Why? Why would this happen?