jQuery: go to URL with target=“_blank”

2019-01-13 02:49发布

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!

7条回答
Bombasti
2楼-- · 2019-01-13 03:53

You need to open a new window:

window.open(url);

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

查看更多
登录 后发表回答