在javascript中的ajax响应之后在新选项卡中打开

时间:2022-10-07 08:26:08

Open in new tab after ajax response in javascript is not working,

在javascript中的ajax响应不起作用后,在新选项卡中打开,

tried with _newtab and _blank

试过_newtab和_blank

But none of them is working,

但是他们都没有工作,

I say,

Is there any solution to get the answer ?

有没有解决方案可以得到答案?

4 个解决方案

#1


5  

From JavaScript, you cannot open new tabs. You can only open new windows. It's up to the user's browser settings how it opens new windows (be it in a new tab, a new tab in the background, or a new window).

从JavaScript,您无法打开新标签。您只能打开新窗口。这取决于用户的浏览器设置如何打开新窗口(无论是在新选项卡中,在后台的新选项卡还是新窗口)。

JavaScript does not and cannot even know if your browser supports tab. And it does not have access to anything on the outsides of the browser (unless there's leverage from an extension I suppose).

JavaScript不会甚至不知道您的浏览器是否支持选项卡。并且它无法访问浏览器外部的任何内容(除非我认为扩展具有杠杆作用)。

And as a reminder, there are browsers with no tabs, and others with no windows even. Tabs are just browser features, and never part of any language specification.

作为提醒,有些浏览器没有标签,有些甚至没有窗户。选项卡只是浏览器功能,绝不是任何语言规范的一部分。

#2


2  

Use this -> window.open(YourUrlInsertHere, '_blank');

使用这个 - > window.open(YourUrlInsertHere,'_ blank');

#3


0  

use window.open() method. For more details check this

使用window.open()方法。有关详细信息,请查看此

#4


0  

Above given answer is great to help but in some way, they are not complete working solution and I came here for finding the same solution and will like to add the working example of it.

上面给出的答案很有帮助,但在某种程度上,它们不是完整的工作解决方案,我来到这里寻找相同的解决方案,并希望添加它的工作示例。

var win = window.open('_link is here_', 'name');
if (win) {
    //Browser has allowed it to be opened
    win.focus();
} else {
    //Browser has blocked it
    alert('Please allow popups for this website');
}

'name' is a name of the window. Following names are supported

'name'是窗口的名称。支持以下名称

  • _blank - URL is loaded into a new tab. This is default.
  • _blank - 将URL加载到新选项卡中。这是默认的。

  • _parent - URL is loaded into the parent frame
  • _parent - 将URL加载到父框架中

  • _self - URL replaces the current page
  • _self - URL替换当前页面

  • _top - URL replaces any framesets that may be loaded
  • _top - URL替换可能加载的任何框架集

Depending on the browser's implementation this will work. There is nothing you can do to make it open in a window rather than a tab.

根据浏览器的实现,这将起作用。没有什么可以让它在窗口而不是标签中打开。

Also find the sample example of it here

另请参阅此处的示例示例

#1


5  

From JavaScript, you cannot open new tabs. You can only open new windows. It's up to the user's browser settings how it opens new windows (be it in a new tab, a new tab in the background, or a new window).

从JavaScript,您无法打开新标签。您只能打开新窗口。这取决于用户的浏览器设置如何打开新窗口(无论是在新选项卡中,在后台的新选项卡还是新窗口)。

JavaScript does not and cannot even know if your browser supports tab. And it does not have access to anything on the outsides of the browser (unless there's leverage from an extension I suppose).

JavaScript不会甚至不知道您的浏览器是否支持选项卡。并且它无法访问浏览器外部的任何内容(除非我认为扩展具有杠杆作用)。

And as a reminder, there are browsers with no tabs, and others with no windows even. Tabs are just browser features, and never part of any language specification.

作为提醒,有些浏览器没有标签,有些甚至没有窗户。选项卡只是浏览器功能,绝不是任何语言规范的一部分。

#2


2  

Use this -> window.open(YourUrlInsertHere, '_blank');

使用这个 - > window.open(YourUrlInsertHere,'_ blank');

#3


0  

use window.open() method. For more details check this

使用window.open()方法。有关详细信息,请查看此

#4


0  

Above given answer is great to help but in some way, they are not complete working solution and I came here for finding the same solution and will like to add the working example of it.

上面给出的答案很有帮助,但在某种程度上,它们不是完整的工作解决方案,我来到这里寻找相同的解决方案,并希望添加它的工作示例。

var win = window.open('_link is here_', 'name');
if (win) {
    //Browser has allowed it to be opened
    win.focus();
} else {
    //Browser has blocked it
    alert('Please allow popups for this website');
}

'name' is a name of the window. Following names are supported

'name'是窗口的名称。支持以下名称

  • _blank - URL is loaded into a new tab. This is default.
  • _blank - 将URL加载到新选项卡中。这是默认的。

  • _parent - URL is loaded into the parent frame
  • _parent - 将URL加载到父框架中

  • _self - URL replaces the current page
  • _self - URL替换当前页面

  • _top - URL replaces any framesets that may be loaded
  • _top - URL替换可能加载的任何框架集

Depending on the browser's implementation this will work. There is nothing you can do to make it open in a window rather than a tab.

根据浏览器的实现,这将起作用。没有什么可以让它在窗口而不是标签中打开。

Also find the sample example of it here

另请参阅此处的示例示例