JQuery: go to URL with target=”_blank”

hrefjquerytargeturl

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!

Best Answer

You need to open a new window:

window.open(url);

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