我在html unload事件上调用了一个javascript函数,但它只适用于google chrome而不是firefox和IE。
<script>
function fun()
{
$.post("test.php",{name:'name'},function(data){alert(data);})
}
</script>
<body onUnload="fun()">
</body>**emphasized text**
答案 0 :(得分:1)
也许你想使用onbeforeunload。 Safari,IExplorer,Firefox,Opera和Chrome都支持。
一个基本的例子:
<html>
<head>
<script type="text/javascript">
window.onbeforeunload = OnBeforeUnLoad;
function OnBeforeUnLoad () {
return "bye world!";
}
</script>
</head>
<body>
<b>Close or reload the page.</b>
</body>
</html>