Lets make IT better by sharing the solutions

Monday, July 14, 2008

Trapping Window Close for Internet Explorer

Today i come across a scenario where , if the close button of internet explorer is clicked and i need to call a logout action to have safe signout.So i scroll through internet all the way , I came to know about so many ways but non of them worked for me . But i got the clue how to proceed , I proceed as
Place the follwing java script code on your page between script tag

function whileClosing() {
if((window.event.clientX>1000)(window.event.clientY<-100)) {
document.forms[0].action="<%=sLinkPrefix%>/logoutAction.do";
document.forms[0].submit(); }
else { alert("Refresh"); }
}
window.onunload=whileClosing;
Here clientX,clientY is the location where the click is done so better you alert these locations and check what are the coordinated of close button,
Note : This might be different Coordinated for other Resolutions.Please check to trap the resolutions of your system and let me know if you are done.

No comments: