0

I need to perform different actions based on the way a popup window is closed

I assume there are two ways to close a popup window,

  • Click the close button on the popup window
  • use window.close function

Is there a way to determine which way is used when a popup window closes?

xiaohan2012
  • 8,986
  • 20
  • 64
  • 99

2 Answers2

1

try this..

var myWindow = window.open('yourpage.php','test page','width=640,height=480');
var newwindow = false;
myWindow.onunload = function() {
    if (myWindow.closed) {
        alert("Window Closed by Your function");
    } else if(myWindow && newwindow){
        alert("Window Closed by close button");
    } else{
        newwindow = true;
    }
};

the newwindow variable used to handle the onunload function executed during opening the window.

Krishna Raj
  • 826
  • 11
  • 33
1

AFAIK, no. Relevant.

Detecting the browser closing at all is hairy, let alone detecting how it was closed.

Community
  • 1
  • 1
simshaun
  • 21,019
  • 1
  • 56
  • 73