使用jQuery打开新标签页中的所有链接 [英] Open all links in new tabs with jQuery
本文介绍了使用jQuery打开新标签页中的所有链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些链接通过JSON动态放置在页面中,无法直接对其进行编辑.我想强制所有链接在新选项卡中打开,例如target="_blank"
I have some links that are placed in my page dynamically via JSON and have no way to directly edit them. I want to force all links to open in new tabs, ala target="_blank"
以为这会起作用..可惜的是,它没有.有什么想法吗?
Thought this would work.. but sadly it isn't. Any ideas?
$('a').attr("target","_blank");
这是带有动态代码的jsFiddle: http://jsfiddle.net/danielredwood/mrgta/7/
Here's a jsFiddle with the dynamic code: http://jsfiddle.net/danielredwood/mrgta/7/
推荐答案
您可以执行此操作(这使用户浏览器可以决定是否打开新窗口或标签页)
You could do this (which lets the users browser decide whether to open a new window or tab)
$('a').live('click', function() {
window.open($(this).attr('href'));
return false;
});
这篇关于使用jQuery打开新标签页中的所有链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文