2

I want click button open new tab but it alway open new window:

window.open(my_id + '/edit/', '_blank', 'rel="noopener"')

Require using rel="noopener"

2 Answers2

2

I think the below code will help you to solve the problem

window.open('_link is here_', 'name');

Function description: name is a name of the window.

Following names are supported:

_blank - URL is loaded into a new tab. This is default.

_parent - URL is loaded into the parent frame

_self - URL replaces the current page

_top - URL replaces any framesets that may be loaded

OR you can try this method also

var win = window.open('https://www.google.co.in/', '_blank');
if (win) {
    //Browser has allowed it to be opened
    win.focus();
} else {
    //Browser has blocked it
    alert('Please allow popups for this website');
}
Hari17
  • 481
  • 1
  • 4
  • 12
  • thanks, I solve the problem just remove `rel="noopener"` :D, no need any more –  Mar 09 '18 at 05:35
0

If you don't specify the third parameter, your URL is most likely to open in a new tab, instead of a new window.

Per the documentation of window.open:

windowFeatures : A DOMString containing a comma-separated list of window features given with their corresponding values in the form "name=value". These features include options such as the window's default size and position, whether or not to include scroll bars, and so forth. There must be no whitespace in the string. See Window features below for documentation of each of the features that can be specified.

So, if you omit that, a tab will be opened. But this will defeat the purpose of using noopener.

31piy
  • 23,323
  • 6
  • 47
  • 67
  • thanks, I solve the problem just remove `rel="noopener" :D`, no need any more –  Mar 09 '18 at 05:35