So I have an onclick that directs to a linkedin page here:
<li id="toHover" onclick=" window.open('https://www.linkedin.com/in/jvanderkooi/?originalSubdomain=nl','_blank')" ><a naam="" data-placement="top" data-toggle="tooltip" data-original-naam="LinkedIn"><i ></i></a></li>
This works great, it opens a new window with the provided url and leaves the other one open. However, I dont want to use this in-build url but want this element to get the url attribute of a certain user. Something like this:
<li id="toHover" onclick="window.open(user.linkedinURL, 'new_window')"
><a naam="" data-placement="top" data-toggle="tooltip" data-original-naam="LinkedIn"><i ></i></a></li>
When i do this, a new window opens up the root of my web app. Im currently running this on localhost only so I get to http://localhost:8080 where my app is running instead of the linkedin page url provided.
I tried doing this a bunch of different ways but just can't seem to get it to work. What am I missing here?
CodePudding user response:
Maybe your user.linkedinURL
without 'https' or 'http'.
Also you could write a function with url parameter.
const openUrl = new function(url){
window.open(url);
}
After in HTML use for example onclick="openUrl('https://www.linkedin.com/in/jvanderkooi/?originalSubdomain=nl');
;
CodePudding user response:
It is due to anchor a
element inside the li
.
Use the below
<li id="toHover" onclick="window.open(user.linkedinURL, 'new_window')" ></li>
If you need to use a
tag, then you can try this and specify target blank
<li id="toHover"
><a naam="" target="_blank" href="user.linkedinURL" data-placement="top" data-toggle="tooltip" data-original-naam="LinkedIn"><i ></i></a></li>