javascript function does not work
This is my chats' sign out function. It works perfectly when I open the chat on a page alone.e.g. www.example.com/chatbox/index.htm But when its with other elements in the same page using iFrame it will not work.e.g.www.example.com/chat&paintIframe.htm
This is my code
<script type="text开发者_如何学C/javascript">
function singout(){
data="user=" + "" +"&oper=signout"
Ajax_Send("POST","chatbox/users.php",data,checkSignOut);
alert("Singout");
return false;
}
</script>
and here I call it
<iframe height="300" width="600" frameborder="0" src="chatbox/index.htm" onbeforeunload="singout()"></iframe>
I'm gonna go out on a limb here and say that there isn't an issue with the function, but instead with what you expect onbeforeunload
to do. I believe you expect that if the browser is closed, or the user navigates away from the page it will execute the event onbeforeunload, which is unfortunately not the case, or at least it will not be consistent.
The best method of ensuring that the user is logged out when they no longer have the browser open is instead to use ajax to make a call to the server every few seconds. If the call is made then successfully refresh the session, if it is not successful then you have nothing to worry about really because the session will timeout on its own after a certain amount of time.
精彩评论