In this post i would discuss a simple workaround to the fact that ADF 11g does not support a explicit window close event. The workaround is to use a library like dojo or jquery. One should use these libraries as it will make the function cross browser compatible. The code mentioned below logs the user out when they press the close button on browser. It essentially calls the unLoad function which makes the use of dojo.io.script.get function (this dojo function also allows cross site data access using callbacks).
1 2 3 4 5 6 7 8 9 10 11 12 13 | <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js" ></script> <script type="text/javascript"> dojo.require("dojo.io.script"); var unLoad = function() { dojo.io.script.get({ url:'http://127.0.0.1:7101/myapp/adfAuthentication?logout=true', timeout:15000, }); } dojo.addOnWindowUnload(unLoad); </script> |
Add this code in the fragment or the jspx page. Also note that if you are adding it in a fragment make sure to add the script in a af:panelFormLayout. ** Note:** The documentation states the following.
1 2 3 4 5 6 | However, you need to be careful about what work you do during dojo.addOnUnload/window.onbeforeunload since this event can be triggered if the user clicks a link to download a file or a javascript: link. In these cases, the document will not be destroyed and so any destructive operations done during a dojo.addOnUnload callback may be premature. |
Therefore you will have to ignore such events by using something like this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <script type="text/javascript"> dojo.require("dojo.io.script"); var doUnload=true; var unLoad = function() { if(doUnload){ dojo.io.script.get({ url:'http://127.0.0.1:7101/myapp/adfAuthentication?logout=true', timeout:15000, }); } doUnload=true; }; var init=function(){ dojo.connect(dojo.doc, "onkeypress", function(e){ switch(e.charOrCode){ case dojo.keys.F5: doUnload=false; break; case dojo.keys.BACKSPACE: doUnload=false; } dojo.stopEvent(e); }); dojo.connect(dojo.doc, "onclick", function(e){ doUnload=false; }); }; dojo.addOnWindowUnload(unLoad); dojo.addOnLoad(function (){init();}); </script> |