On Close event in xPages

Is there a way to catch the unload or close event of a window in xPages? Dojo has an addOnUnload(), but I couldn’t get it to work.

Thanks,

Scott.

Subject: Use a script block…

<xp:scriptBlock>		<xp:this.value escape="false">

		window.onunload=function() {

			alert('I run on window unload');

		}

	</xp:this.value>

</xp:scriptBlock>
  • You must use the nested value tag, otherwise you can’t prevent it from escaping the text, which ruins the script. Or that was my experience yesterday. Seems sort of senseless to automagically escape script, but there it is. At least there’s a way around it.

  • And “inline” server-side code works as well, so:

    alert(‘Session var is ${sessionScope.var}’); will use the sessionScope.var as expected.

  • Caveat is the same as any onunload function … it tends to run at other times, like page refresh, but this works to initialize it.

Hope this helps…

Subject: Calling a function in a server side script lib.

So what I’m trying to do is call a funtion in a server side script lib with the onclose. The function is called ‘closeConnection()’, which closes a SQL connection ‘sessionScope.sqlConn.closeConnection()’

Any ideas?

Thanks,

Scott