I want to detect if the user pressed the browser's close button on a popup window in my application.
By searching around I found this solution:
$(window).bind('beforeunload', function(event) {
$.ajax({url:"acquisition_cleanup.php", async:false});
var dataStr = 'id={id}';
$.ajax({
type: "POST",
url: "acquisition_cleanup.php",
data: dataStr,
success: function() {
window.close();
}
});
});
It works well on my Ubuntu machine with Firefox 31. But unfortunately it does not work on windows machine with the same Firefox-Browser. How can I fix this issue?
// EDIT
This is the function I use to open the window:
function popup (url) {
win = window.open(url, "Fenster", "width=1200,height=600,resizable=yes,menubar=no,toolbar=no,status=no,location=no,directories =no");
win.focus();
return false;
}
EDIT 2 //
I added this to the global.js
function checkWindowClosed(url, progress) {
var yourwindowname; // add in Global
if(yourwindowname==undefined){
var param= "toolbar=no,scrollbars=1";
yourwindowname=window.open(url, "Fenster", param);
}else{
yourwindowname.focus();
}
var timer = setInterval(function() {
if(yourwindowname.closed) {
clearInterval(timer);
progress();
alert("Popup Closed");
}else{
yourwindowname.close();
}
}, 1000);
}
And in the HTML-File I used the function like this, but it still does not work:
checkWindowClosed("aquisition.php", function() {
$.ajax({url:"acquisition_cleanup.php", async:true});
var dataStr = 'id={id}';
$.ajax({
type: "POST",
url: "acquisition_cleanup.php",
data: dataStr,
success: function () {
window.close();
}
});
});