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);