Reputation: 121
Is there a way to get anchor tags to open in a new window instead of the current one?
<a href="my_link">Link</a>
Upvotes: 8
Views: 47766
Reputation: 437
you no need to write such long javascript to do with your requirement. Just set target attribute to _blank in your anchir tag itself. whenever a user click on that link it will open in new tab. sample tag is as follow
<a href="www.google.com" target="_blank">Google</a>
Hope this helps you
NOTE: For Security reason
Upvotes: 8
Reputation: 31
The easiest way is to do:
<a href="https://www.google.com/" target="new">Google</a>
This will open whatever the link given in a new tab.
Upvotes: 3
Reputation: 1692
This will work but its pure javascript
<a href="http://www.snopzer.com" onclick="window.open(this.href, 'Snopzer',
'left=20,top=20,width=500,height=500,toolbar=1,resizable=0'); return false;" >Open Link</a>
Upvotes: 4
Reputation: 687
Use jQuery/javascript to open in new window
$('a').click(function(){
window.open('http://google.com')
});
Upvotes: -18
Reputation: 943579
Set the target
attribute to _blank
.
You have no control over what sort of new "window" the browser will open it in. It might be an actual window, it might be a tab, it might be overridden and forced to the same window.
It is, however, a bad idea, so don't do it, really, please don't.
Upvotes: 41