简体   繁体   中英

javascript function does not work

This is my chats' sign out function. It works perfectly when I open the chat on a page alone.eg www.example.com/chatbox/index.htm But when its with other elements in the same page using iFrame it will not work.egwww.example.com/chat&paintIframe.htm

This is my code

<script type="text/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM