开发者

Make every link on my blog open in another window with jQuery

With the mighty aid of the jQuery library, how can I have every link on my blog open in another window?

Instead开发者_StackOverflow社区 of putting target="_blank" on every link, is there a way I can shortcut this with the use of jQuery?


you don't need jQuery

insert this to your <header>

<base target="_blank" />

see more: http://www.w3schools.com/TAGS/tag_base.asp


Uh, I guess you could do something like this:

$('a.newWindow').click(function() {
    var href = $(this).attr('href');
    if(href.length > 0) {
       window.open(href);
    }
});

Or, just do it the right way:

$('a.newWindow').attr('target', '_blank');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜