我需要打开一个弹出窗口,然后关闭弹出窗口(刷新父页面)
jquery 'beforeunload' 事件在 Internet Explorer 8,9 中不起作用。
我的代码是:
/*
* events
* add tallyman
*/
$("div.main form div.tallymanlist").click(function() {
if(gencargo.show_confirm('Add new tallyman?')) {
var windowObject = gencargo.windowOpener(600,1400, "Tallyman",$(this).children().attr("url"));
gencargo.windowParentRefresh(windowObject);
}
});
gencargo 对象是内容(窗口打开):
/*
* open window
*/
windowOpener : function (windowHeight, windowWidth, windowName, windowUri) {
var centerWidth = (window.screen.width - windowWidth) / 2;
var centerHeight = (window.screen.height - windowHeight) / 2;
newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth +
',height=' + windowHeight +
',left=' + centerWidth +
',top=' + centerHeight);
newWindow.focus();
return newWindow;
},
还有窗口关闭:
windowParentRefresh : function(object) {
$(object).bind('beforeunload', function () {
object.opener.location.reload();
});
}
关闭窗口事件在 ie 中不起作用。仅适用于 FireFox、Chrome、Opera。
最佳答案
试试这个:
/*
* reload page
*/
windowParentRefresh: function(object) {
setTimeout(function() {
setTimeout(function() {
$(object).bind('beforeunload', function() {
object.opener.location.reload();
});
}, 1000);
},1);
}
关于JavaScript 'beforeunload' 事件在 ie 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8152361/