从它的父级关闭一个子窗口

时间:2012-09-13 08:54:12

标签: javascript jquery

我目前有以下代码来生成一个新的子窗口。我还为用户设置了超时响应,当超时结束时,应该关闭子窗口。

这是我到目前为止所得到的:

 var zerominutpopup 'http://www.somewebsite.com/';
zerominutpopup = open(zerominutpopup, '', 'height=300,width=600,left=300,top=300');
setTimeout( function(){ timer_is_at_zero_hold(zerominutpopup); }, 10000);


function timer_is_at_zero_hold(windowtoclose){
windowtoclose.closed;// this is how (i thought) closing a window is done but doesnt seem to work.
}

1 个答案:

答案 0 :(得分:5)

var chWnd = window.open(...);  //open window and save a reference to it

chWnd.close();   // use that reference to access that 'window' object's members

所以你原来的代码应该是......

var zerominutepopup = window.open(url, '', 'height=300,width=600..');
setTimeout( function(){ 
    zerominutepopup.close(); 
}, 10000);