Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.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 ajax调用成功后如何关闭浏览器中当前打开的选项卡_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript ajax调用成功后如何关闭浏览器中当前打开的选项卡

Javascript ajax调用成功后如何关闭浏览器中当前打开的选项卡,javascript,jquery,ajax,Javascript,Jquery,Ajax,下面是我的ajax调用,一旦ajax调用成功,我想从浏览器关闭当前选项卡 $.ajax({ type: "GET", data: null, url: '@Url.Action("SessionKill", "Authentication")', dataType: 'json', contentType: false, processData: false, success: function (response) { i

下面是我的ajax调用,一旦ajax调用成功,我想从浏览器关闭当前选项卡

$.ajax({
    type: "GET",
    data: null,
    url: '@Url.Action("SessionKill", "Authentication")',
    dataType: 'json',
    contentType: false,
    processData: false,
    success: function (response) {
        if (response != null && response.success) {
            window.location = window.close();//from here,I want to close the tab.
        }
    },
    error: function (response) {
    }
});

你打错了。试试这个:

element.close();
代替:

window.location = window.close();
window.close只能关闭使用window.open打开的窗口,因此无法关闭javascript中的当前选项卡。您可以打开一个新窗口,将其存储在变量中,然后关闭它

打开窗口时:

var风;
函数openWindow(){
风=窗户。打开(“https://www.google.com/“风”,“宽=1000,高=700”);
}
函数closeWindow(){
风。关闭();
}

这对我很有用:

if (response != null && response.success) {
    window.open('', '_self', ''); 
    window.close();
}

无法关闭未使用javascript打开的窗口/选项卡


如果你用window.open()创建一个窗口,你可以用window.close()关闭它,否则你不能用js关闭它。

我也试过了,但它不起作用,这就是为什么我发布了这个问题。虽然不需要,这不会影响关闭窗口
窗口。关闭
只能关闭使用
窗口打开的窗口。打开
则无法关闭javascript中的当前选项卡。您可以打开一个新窗口,将其存储在变量中,然后关闭它。现在看起来好多了@ShaunParsons这里的
元素
是什么意思@ShaunParsons?您是如何确认调用了
成功:
函数的?
window.close()
在没有
调用的情况下工作正常吗?如果是这样的话,那就不是问题所在。向
成功:
错误:
添加警报-可能您收到了错误,但忽略了它?没有错误,window.close()只能关闭使用window.open()打开的窗口;成功正在呼叫。它将重新打开同一选项卡。实际上我不需要该选项卡,我只想关闭该选项卡。