user5154997
user5154997

Reputation:

Open new tab using jquery

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"

Upvotes: 2

Views: 3894

Answers (2)

31piy
31piy

Reputation: 23859

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.

Upvotes: 0

Hari17
Hari17

Reputation: 489

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');
}

Upvotes: 2

Related Questions