onbeforeunload 在每个页面打开后调用
我对 onbeforeunload 有疑问。我只想在关闭浏览器后删除一些表的数据。它适用于所有浏览器,但不适用于 IE。当我在 IE 中工作时,如果我转到另一个链接,onbeforeunload 函数就会执行,但其他浏览器只有在关闭后才会执行。
我的代码是
<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="fnUnloadHandler()">
</body>
请帮帮我..
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="fnUnloadHandler()">
</body>
please help me out..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 jQuery 库,它基于 javascript,它可以为您处理所有这些浏览器不兼容问题。
You can go for the jQuery library, it is based on javascript, it handles all these browser incompatibilities for you.