There are any number of questions on this topic out there, but I have not seen my situation addressed so I will describe my scenario.
I have a popup window. There are 2 ways you can close it: pressing a close button within the popup window or by pressing the x button in the upper right hand corner of the window. They have the exact same effect. If I could disable the x I would, but that is unnecessary and not happening anytime soon in your favorite browser. In essence, I am doing some post-processing when the window is closed (session clean-up actually) and am not spawning endless new popup windows to annoy my users. Trust me, the customer asked for this behavior.
So I could do window.onunload or I can do the body onunload and either way will give me the results I wish. However, there is a third scenario which complicates matters. Within the popup window, there can be a form submission which alters the contents of that popup window. If this is the case, either window.onunload or body unload will be invoked, depending upon which I have setup on my page. This is not what I want. I want the post-processing to happen upon the popup window visually disappearing from sight (x or close button), but not to post-process when a form submission has taken place leaving the popup still visually on this screen.
Can anyone speak to this scenario?
EDIT: My attempt at a solution which does not trigger window.onunload
function searchFieldTitles()
{
var searchOptionValue;
var radioObj = document.getElementsByName("searchOption");
var radioLength = radioObj.length;
for(var i = 0; i < radioLength; i++) {
if(radioObj[i].checked) {
searchOptionValue = radioObj[i].value;
break;
}
}
$.get("/myroot/SearchFieldTitles.action",
{filterString: document.getElementsByName("filterString")[0].value,
searchOption: searchOptionValue,
filterBy: document.getElementsByName("filterBy")[0].value},
function(data) {
});
location.href="/myroot/jsp/field_titles/lookupFieldTitles.jsp";
}