Javascript jQuery:如何检测弹出窗口是否关闭?
我想检测用户是否在我的应用程序的弹出窗口上按下了浏览器的关闭按钮 通过四处搜索,我找到了以下解决方案:Javascript jQuery:如何检测弹出窗口是否关闭?,javascript,jquery,javascript-events,window,Javascript,Jquery,Javascript Events,Window,我想检测用户是否在我的应用程序的弹出窗口上按下了浏览器的关闭按钮 通过四处搜索,我找到了以下解决方案: $(window).bind('beforeunload', function(event) { $.ajax({url:"acquisition_cleanup.php", async:false}); var dataStr = 'id={id}'; $.ajax({ type: "POST", url
$(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();
}
});
});
它在我的Ubuntu机器和Firefox31上运行良好。但不幸的是,它不能在使用相同Firefox浏览器的windows机器上工作。如何解决此问题?谢谢你的帮助
//编辑
这是我用来打开窗口的函数:
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;
}
编辑2//
我把这个添加到了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);
}
在HTML文件中,我使用了如下函数,但仍然不起作用:
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();
}
});
});
您可以试试这个,您可以使用下面的代码来检查浏览器弹出窗口的关闭状态
var yourwindowname; // add in Global
/*Added this for to open a browser popup window */
if(yourwindowname==undefined){
var param= "toolbar=no,scrollbars=1";
yourwindowname=window.open("your url here", 'yourwindowname', param);
}else{
yourwindowname.focus();
}
/* Added this to Check the popup closed status - In your case on ajax success event */
var timer = setInterval(function() {
if(yourwindowname.closed) {
clearInterval(timer);
//do your process here
alert("Popup Closed");
}else{
yourwindowname.close();
}
}, 1000);
工作项目的更新代码:使用以下代码而不是当前的javascript函数
function popup (url) {
if(win==undefined){
win = window.open(url, "Fenster", "width=1200,height=600,resizable=yes,menubar=no,toolbar=no,status=no,location=no,directories=no");
}else{
win.focus();
}
return false;
}
function checkWindowClosed(){
var timer = setInterval(function() {
if(win.closed) {
clearInterval(timer);
progress();
alert("Popup Closed");
}else{
win.close();
}
}, 1000);
}
$.ajax({
type: "POST",
url: "acquisition_cleanup.php",
data: dataStr,
success: function () {
checkWindowClosed();
}
});
您使用的是哪种弹出窗口?我可以马上给你关于引导弹出窗口的答案,但我不知道你是不是这么想的want@user3127242我对此表示怀疑,因为在问题或标签中没有任何提及。我在原始帖子中添加了代码。PS:我需要检查弹出窗口是否在弹出窗口中关闭,因为索引没有必要的数据。。。