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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
xiaohan2012
  • 9,870
  • 23
  • 67
  • 101

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
  • 846
  • 1
  • 12
  • 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,263
  • 1
  • 57
  • 73