如何在javascript中关闭子窗口时调用父窗口函数?
现在,当我关闭这个子窗体时,在它关闭之后,我想调用DoABC函数 我尝试使用子窗口的window.onbeforeunload事件,但它对我无效如何在javascript中关闭子窗口时调用父窗口函数?,javascript,jquery,html,dom,Javascript,Jquery,Html,Dom,现在,当我关闭这个子窗体时,在它关闭之后,我想调用DoABC函数 我尝试使用子窗口的window.onbeforeunload事件,但它对我无效 //Parent page javascript function DoABC() { //my logic goes here } function btnClick() //This function gets fired on the click event of a button which will open a child wi
//Parent page javascript
function DoABC()
{
//my logic goes here
}
function btnClick() //This function gets fired on the click event of a button which will open a child window now
{
window.open("childpage.html", "_blank", "height=400, width=550, status=yes, toolbar=no, menubar=no, location=no, addressbar=no");
}
此问题的解决方案是什么?当您调用window.onbeforeunload时,您指的是当前的窗口对象。我认为这是可行的:
window.onbeforeunload = function(event) {
event = event || window.event;
var confirmClose = 'Are you sure?';
// For IE and Firefox prior to version 4
if (event) {
event.returnValue = "Are you sure";
}
// For Safari
return confirmClose;
}
我还没有试过,但我认为这会解决您的问题。newWin.onbeforeonload=function(){alert(“hello”);}不起作用。
var newWin = window.open(....);
newWin.onbeforeonload = function () {....}