Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
134
rated 0 times [  137] [ 3]  / answers: 1 / hits: 32306  / 11 Years ago, sun, july 28, 2013, 12:00:00

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.


More From » html

 Answers
11

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

[#76690] Friday, July 26, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jesse

Total Points: 513
Total Questions: 118
Total Answers: 106

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
;