Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 570
Sangram Singh Avatar asked Jul 28 '13 06:07

Sangram Singh


1 Answers

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');")
like image 131
jcsanyi Avatar answered Nov 14 '22 20:11

jcsanyi