How can I make a HTML a href hyperlink open a new window?

HtmlHyperlinkwindow.location

Html Problem Overview


This is my code:

<a href="http://www.google.com" onClick="window.location.href='http://www.yahoo.com';return false;" target="_blank">test</a>

When you click it, it takes you to Yahoo but it does not open a new window?

Html Solutions


Solution 1 - Html

<a href="#" onClick="window.open('http://www.yahoo.com', '_blank')">test</a>

Easy as that.

Or without JS

<a href="http://yahoo.com" target="_blank">test</a>

Solution 2 - Html

In order to open a link in a new window, add Javascript command

onclick="window.open('text-link.htm', 'name','width=600,height=400') inside the <a> tag:

<a href="../html-link.htm" target="popup" onclick="window.open('../html-link.htm','name','width=600,height=400')">Open page in new window</a>

Solution 3 - Html

Given answer might be helpful when you want to open a new tab or browser user preference is set to open new window instead of tab, since the original question is about open new window not a tab, here is what works for me.

<a href="#" onClick='window.open(url, "_blank", "resizable=yes, scrollbars=yes, titlebar=yes, width=800, height=600);'>test</a> 

Check this one too

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTheBlackBenzKidView Question on Stackoverflow
Solution 1 - HtmlJohnView Answer on Stackoverflow
Solution 2 - HtmlAnonymous GirlView Answer on Stackoverflow
Solution 3 - HtmlUttam UgharejaView Answer on Stackoverflow