开发者

onbeforeunload is calling after every page open

开发者 https://www.devze.com 2023-03-13 03:58 出处:网络
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 ano

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消