Javascript 关闭您刚刚打开的选项卡

Javascript close an tab you just opened

本文关键字:选项 Javascript      更新时间:2023-09-26

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

我现在使用:

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

"其他网址"不是域,所以我无法控制该网址。

我该怎么做?

window.open为您提供了对该窗口的引用,因此:

var newWindow = window.open('http://otherurl.com', 'newwindow', 'width=300, height=250');
setTimeout(function() { newWindow.close(); }, 5000);