0

onbeforeunload is cancelling all event

asked 2009-05-17 21:34:08 +0800

sousa1981 gravatar image sousa1981
573 4

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>

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2009-06-05 11:48:38 +0800

sousa1981 gravatar image sousa1981
573 4

I think it will not help, try to investigate it in more detail.

Regards,

link publish delete flag offensive edit

answered 2009-06-04 18:14:58 +0800

yuryg gravatar image yuryg
3

Hi all,

sousa1981, you can try to use Monitor interface. This help to detect moment when desktop is destroyed (when you close/refresh tab).

link publish delete flag offensive edit

answered 2009-05-19 11:12:13 +0800

sousa1981 gravatar image sousa1981
573 4

Hi Dennis,

Thank you more one time. I understand that I can't send event.

I catch the way I can do it. I will make an REST to logout from Javascript, something like this.

link publish delete flag offensive edit

answered 2009-05-19 08:11:50 +0800

dennis gravatar image dennis
3669 1 6
http://www.javaworld.com....

updated 2009-05-19 08:12:19 +0800

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...

link publish delete flag offensive edit

answered 2009-05-19 06:57:13 +0800

sousa1981 gravatar image sousa1981
573 4

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,

link publish delete flag offensive edit

answered 2009-05-19 06:09:25 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

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

link publish delete flag offensive edit

answered 2009-05-18 17:47:25 +0800

sousa1981 gravatar image sousa1981
573 4

Is there any workaround to this?

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-05-17 21:34:08 +0800

Seen: 1,066 times

Last updated: Jun 05 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More