jQuery:转到带有target =“" _blank"的URL; [英] jQuery: go to URL with target="_blank"
本文介绍了jQuery:转到带有target =“" _blank"的URL;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下jQuery代码来获取链接的href:
I am using this bit of jQuery code to get href of the link:
var url = $(this).attr('href');
-以及转到该href的这段代码:
-- and this bit of code to go to that href:
window.location = url;
一切都是我想要的方式,除了新页面在与上一个页面相同的窗口中打开,而且我希望它在新窗口或选项卡中打开(通过使用target ="_ blank"公式).
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).
问题:如何使用jQuery在新窗口或选项卡中打开href?
谢谢您的帮助!
推荐答案
您需要打开一个新窗口:
You need to open a new window:
window.open(url);
https://developer.mozilla.org/zh-CN/docs/DOM/window.open
这篇关于jQuery:转到带有target =“" _blank"的URL;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文