开发者

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

开发者 https://www.devze.com 2023-01-10 02:54 出处:网络
With the mighty aid of the jQuery library, how can I have every link on my blog open in another window?

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

精彩评论

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