Sangram Singh
Sangram Singh

Reputation: 7191

How to open link in new Tab by pressing Button? in jade

The following

button(type="button", target="_blank", onclick="location.href='auth/google';")

does not work. It opens link in the same window. Just for reference, its part of node.js program, in which i'm using passportjs for google authentication.

Upvotes: 6

Views: 32455

Answers (1)

jcsanyi
jcsanyi

Reputation: 8174

The button isn't actually opening a link - it's just running some javascript code that happens to, in this instance, be navigating to a new URL. So the target="_blank" attribute on the button won't help.

Instead, you need to use javascript commands to open a new tab/window, rather than using javascript to change the URL of the current window. Assigning to location.href will only change the URL of the current window.

Use the window.open(url, target) function instead - it takes a URL, and a target window name, which behaves the same as the target="whatever" attribute on a link.

window.open('auth/google', '_blank');

Your complete code would look like this:

button(type="button", onclick="window.open('auth/google', '_blank');")

Upvotes: 20

Related Questions