Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.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
关闭选项卡Chrome/Safari浏览器-Javascript_Javascript_Google Chrome_Window - Fatal编程技术网

关闭选项卡Chrome/Safari浏览器-Javascript

关闭选项卡Chrome/Safari浏览器-Javascript,javascript,google-chrome,window,Javascript,Google Chrome,Window,我正在尝试使用javascript关闭Chrome/Safari浏览器选项卡。我尝试了下面所有的代码。但一切都不起作用 open('about:blank', '_self').close(); - This opens up a new tab, and the user is able to browse back. Which is not required. open(location, '_self').close(); - Scripts may close only the win

我正在尝试使用javascript关闭Chrome/Safari浏览器选项卡。我尝试了下面所有的代码。但一切都不起作用

open('about:blank', '_self').close(); - This opens up a new tab, and the user is able to browse back. Which is not required.
open(location, '_self').close(); - Scripts may close only the windows that were opened by it.
window.open('','_parent','');
window.close(); - Not working

这是浏览器限制吗?

window.close不工作,因为它不知道关闭什么。请尝试此操作

//Global var to store a reference to the opened window
var openedWindow;

function openWindow() {
  openedWindow = window.open('moreinfo.htm');
}

function closeOpenedWindow() {
  openedWindow.close();
}


如果您没有使用JavaScript创建它,则可能会重复,您无权关闭它。