onbeforeunload is calling after every page open
I have an issue with onbeforeunload. I just want to delete some tables' data after closing browser. Its working with all browser, however its not working with IE. When I working in IE, if I go to another link, onbeforeunload function executes, but other browser only execute after closing.
my code is
<script language="javascript">
function fnUnloadHandler() {
xmlhttp=null;
if (window.XMLHttpRequest)
{// code for Firefox, Opera, IE7, etc.
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.open("GET","http://yourhost/del_cart_actionFile.php",true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}
</script>
<body onbeforeunload="fnUnloadHan开发者_Go百科dler()">
</body>
please help me out..
You can go for the jQuery library, it is based on javascript, it handles all these browser incompatibilities for you.
精彩评论