Pages

Tuesday, September 28, 2010

OnUnload event in XPages

Add the following script block to your xpage. Preview the same and  close it. Once you close your XPage you will get a prompt which depicts the triggering of the onUnload event in xpages.

 <xp:scriptBlock>
<xp:this.value escape="false">
window.onunload=function() {
alert('I run on window unload');
}
</xp:this.value>
</xp:scriptBlock> 

A little bit of client techniques to include server side scripts will also work here.

Hope this helps:)


2 comments:

  1. I would suggest using dojo.addOnUnload instead of window.onunload. It has better (cross) browser support.

    For the correct syntax, have a look at this blog entry:

    http://www.bleedyellow.com/blogs/m.leusink/entry/xpages_clientside_onload_events3 but

    ReplyDelete
  2. Hi Leus,

    That's a great post. I had tried with dojo.addOnUnload and even gave blind trial on XSP.addOnUnload.

    Both of them failed. They simply did not get triggered when I closed my XPage. Also I am searching for an equivalent to window.onbeforeunload event in XPages. Please share any information about the same if you have any.

    And thanks a lot for the suggestion. Probably I will check dojo.addOnUnload again :)

    Again my trial on XSP.addOnUnload was a bluff and I got my self proved with the help of a great post by Wessel - Meet the XSP Object.

    Hope this helps:)

    ReplyDelete