Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: go to URL with target="_blank"

I am using this bit of jQuery code to get href of the link:

var url = $(this).attr('href'); 

-- and this bit of code to go to that href:

window.location = url; 

Everything is just the way I want it, except the new page opens in the same window as the previous one, and I want it to open in a new window or tab (something that in plain html would have been achieved by using target="_blank" formula).

Question: How can I open the href in the new window or tab with jQuery?

Thank you for your help!

like image 740
Dimitri Vorontzov Avatar asked Jul 13 '11 02:07

Dimitri Vorontzov


People also ask

Can you add target _blank to URL?

You can use the target="_blank" attribute if you want your users to click on a link that opens up a new browser tab. The target="_blank" attribute is used inside the opening anchor tag like this.

Is Target _blank deprecated?

It looks like target="_blank" is still alright. It is listed as a browsing context keyword in the latest HTML5 draft.

Is Target _blank unsafe?

When you link to a page on another site using the target="_blank" attribute, you can expose your site to performance and security issues: The other page may run on the same process as your page.

What should target _blank do when included in a link tag?

A target attribute with the value of “_blank” opens the linked document in a new window or tab. A target attribute with the value of “_self” opens the linked document in the same frame as it was clicked (this is the default and usually does not need to be specified).


1 Answers

You need to open a new window:

window.open(url); 

https://developer.mozilla.org/en-US/docs/DOM/window.open

like image 118
Christopher Armstrong Avatar answered Sep 23 '22 17:09

Christopher Armstrong