I am using this code to update the database while the child browser window close
window.onbeforeunload = check;
function check(){
var url = 'chat_update.php?chatId='+<?php echo $_GET['chatId'];?>;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET",url + Math.random(),false);
xmlhttp.send();
return false;
}
it’s working fine but check() function still calling when the child browser window refresh. Any solution to call the function only on child window close ?
There is no way to determine if the window is getting closed or refreshed (see the docs, especially the To Invoke part). But from within your main window you could check, if the child window is closed, after the
onbeforeunloadevent fired (I assume that you have a reference in your main window to your child window).