Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 关闭刚刚打开的选项卡_Javascript_Url - Fatal编程技术网

Javascript 关闭刚刚打开的选项卡

Javascript 关闭刚刚打开的选项卡,javascript,url,Javascript,Url,我想在一个新窗口中打开一个URL,在x秒后或页面加载完毕后,我想再次关闭它 我现在使用: window.open('http://otherurl.com', 'newwindow', 'width=300, height=250'); return false; “otherurl”不是域,因此我无法控制该URL 如何执行此操作?window.open提供对该窗口的引用,因此: var newWindow = window.open('http://otherurl.com', 'newwi

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

我现在使用:

window.open('http://otherurl.com', 'newwindow', 'width=300, height=250'); return false;
“otherurl”不是域,因此我无法控制该URL

如何执行此操作?

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

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

setTimeout(function() { newWindow.close(); }, 5000);

window.close关闭窗口tab@JordanHendrix即关闭当前选项卡?我想关闭我刚刚打开的新标签Hanks,就是这样!是否有一种可能的方法在它完全加载时关闭它?为了安全起见,我不知道如果没有与其他站点的协调,您如何能够做到这一点。您不能从查看其他域的窗口进行读写。@MatthewDotcom,虽然您不知道外部页面何时已完全加载,但可以通过向setTimeout函数添加额外的时间进行补偿。