-1

It is possible to create popup window with JavaScript and when it id closed detect whether it was closed by user by clicked [X] or by internal JavaScript function? something like,

var win = window.open("someurl", "popup", "");
var pollTimer = window.setInterval(function() {
    if (win.closed !== false) { 
        window.clearInterval(pollTimer);
        detectCloseMethodFunction();
    }
}, 200);
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

0

You could try:

confirm("My popup!");

This would create a browser popup and you can check for the answer.

Check here for more information: http://www.w3schools.com/jsref/met_win_confirm.asp

Massimo Rosin
  • 163
  • 1
  • 13
0

The only relevant events for this question are onunload & onbeforeunload. But still you cannot detect the pressing of the [X] button of the window through them.

Charlie
  • 22,886
  • 11
  • 59
  • 90