1

I am attempting to fire an event on the action of a webpage closing.

The scenario is - a website opens with a separate window, which the user may choose to minimize. This minimized page then waits for the user to either close, or navigate away entirely from the main page before proceeding with a script.

I have looked at the jQuery unload() method, but I don't think it's specific enough i.e. it fires on any kind of navigation (refresh, menu nav etc.)

Is it possible to use this, or another method to achieve this action?

Andyjm
  • 325
  • 3
  • 21
  • 1
    There is no "CLOSE" event. The child can ping the parent and if it does not respond, you can assume it is closed, bunch of ways for that to fail. You should be relying on the serverside session end. – epascarello Jan 12 '15 at 17:06
  • I know, I'm looking for an alternate method to check the session on that webpage has finished – Andyjm Jan 12 '15 at 17:07
  • run a cron job on the back-end to look for stale sessions and close them. – Jonathan Jan 12 '15 at 17:09

2 Answers2

1

Well, this is just not possible as there is no WINDOW_CLOSED event because window objects displayed like main window of a browser fall under the rights of the underlying OS. Even in cases where TDI( Tabbed Documents Interface ), like Microsoft's MDI is implemented in the browsers, no event is fired upon closing of a tab.

Akki
  • 112
  • 12
-1

var winObj = null; var SixView = function (a,b,c) { var popUpPageUrl = "../ViewDrawing.aspx?a=" + $('[id*=hdnAhuId]').val() + "&compPosition=" + spobtId + "&sectionName=" + c; winObj = myOpenWindow(popUpPageUrl, "myWin", winObj); }

function myOpenWindow(winURL, winName, winObj) {
    var theWin; // this will hold our opened window 

    // first check to see if the window already exists
    if (winObj != null) {
        // the window has already been created, but did the user close it?
        // if so, then reopen it. Otherwise make it the active window.
        if (!winObj.closed) {
            var result = confirm("Do you want to save the changes made in six view drawing ?");
            if (result) {
                saveChanges();
            }
            winObj = window.open(winURL, winName);
            winObj.focus();
            return winObj;
        }
        // otherwise fall through to the code below to re-open the window
    }

    // if we get here, then the window hasn't been created yet, or it
    // was closed by the user.
    theWin = window.open(winURL, winName);
    return theWin;
}