TheBlackBenzKid
TheBlackBenzKid

Reputation: 27087

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

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?

Upvotes: 76

Views: 277541

Answers (4)

Marco Aur&#233;lio
Marco Aur&#233;lio

Reputation: 21

to open in a window.

<a href="http://www.google.com" onclick="window.open(this.href, 'new', 'popup'); return false;">Open in a window</a>

Upvotes: 2

Anonymous Girl
Anonymous Girl

Reputation: 642

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>

Upvotes: 5

Uttam Ughareja
Uttam Ughareja

Reputation: 1345

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

Upvotes: 1

John
John

Reputation: 2755

<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>

Upvotes: 137

Related Questions