jQuery add target=“_blank” for outgoing link

后端 未结 15 1789
滥情空心
滥情空心 2020-12-13 04:01

I need some help to create jquery script :)
I have some of link like this on my HTML.

Google


        
15条回答
  •  鱼传尺愫
    2020-12-13 04:45

    $('a').each(function() {
       var a = new RegExp('/' + window.location.host + '/');
       if (!a.test(this.href)) {
          $(this).attr("target","_blank");
       }
    });
    

    This was from css-tricks.com, seems to work pretty well.

提交回复
热议问题