javascript函数不起作用

时间:2010-06-25 18:11:07

标签: php javascript function

这是我的聊天退出功能。当我单独在一个页面上打开聊天时,它可以很好地工作。 www.example.com/chatbox/index.htm 但是当它使用iFrame在同一页面中的其他元素时,它将无法正常工作。例如.www.example.com/chat&paintIframe.htm

这是我的代码

<script type="text/javascript">
function singout(){

data="user=" + "" +"&oper=signout"
Ajax_Send("POST","chatbox/users.php",data,checkSignOut);
alert("Singout");
return false;     
}
</script>

在这里我称之为

<iframe height="300" width="600" frameborder="0" src="chatbox/index.htm"     onbeforeunload="singout()"></iframe> 

1 个答案:

答案 0 :(得分:0)

我会在这里说出这个功能没有问题,而是按照你期望的onbeforeunload来做。我相信你期望如果浏览器关闭,或者用户离开页面,它将执行事件onbeforeunload,但遗憾的是不是这种情况,或者至少它不会是一致的。

确保用户在浏览器不再打开时注销的最佳方法是每隔几秒钟使用ajax调用服务器。如果进行了调用,那么成功刷新会话,如果不成功,那么你没有什么可担心的,因为会话将在一段时间后自行超时。