Javascript关闭您刚刚打开的标签

时间:2016-04-26 15:06:15

标签: javascript url

我想在新窗口中打开一个URL,在x秒后或页面完成加载后我想再次关闭它。

我现在正在使用:

window.open('http://otherurl.com', 'newwindow', 'width=300, height=250'); return false;

'otherurl'不是域名,因此我无法控制该网址。

我该怎么做?

1 个答案:

答案 0 :(得分:7)

window.open为您提供对该窗口的引用,所以:

var newWindow = window.open('http://otherurl.com', 'newwindow', 'width=300, height=250');

setTimeout(function() { newWindow.close(); }, 5000);
相关问题