-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I am trying to send an last event to server after listen tab close, but zk looks like unlisten all events.
The fact, I am not an javascript programmer, so any hekp will be appreciated.
<?xml version="1.0" encoding="utf-8"?> <zk xmlns="http://www.zkoss.org/2005/zul" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:n="http://www.zkoss.org/2005/zk/native" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd"> <window width="200px" height="150px" border="normal" title="Test Javascript 3"> <!-- SERVER --> <zscript> <![CDATA[ private void cleanSession() { alert("clean session..."); } ]]> </zscript> <!-- JAVASCRIPT --> <script type="text/javascript" > <![CDATA[ zk.listen(window, "beforeunload", showMsg); function showMsg() { if (confirm("You are trying exit or refresh.\nDo you want exit?")) { var btn1 = document.getElementsByTagName("button")[0]; comm.sendEvent(btn1, "onClick"); } } function cleanSession3() { var btn1 = document.getElementsByTagName("button")[0]; comm.sendEvent(btn1, "onClick"); } ]]> </script> <button id="btn1" label="BTN 1" onClick="cleanSession()" /> <separator /> <button id="btn2" label="BTN 2" action="onclick: cleanSession3()" /> </window> </zk>
Hi,
Some of the modern browsers may not send a request before closing the browser.
If you want to clean the session, you can specify the session time out.
/Jumper
Hi Jumper,
But, it looked to me like ZK stopped to send a request before closing the browser.
The only browser I need with this is IE 6, 7, 8, ...
We already have an listener implements HttpSessionListener to clean up session objects and invalidate the session.
Do you know an workaround to put the code above to work?
Regards,
Regards,
sousa, after search on the google with key word "cancel beforeunload",
I found, the return value of a function which register to beforeunload must be a String, this stirng is for displaying a confirm message to user by Browser.
you have no way to cancel it, and also no possible to replace with your logic.(showMsg in your code)
So It is not possible to sent a event back to event to server if user decide to close/refresh the tab.
This is browser restriction...
Asked: 2009-05-17 21:34:08 +0800
Seen: 1,070 times
Last updated: Jun 05 '09