jQuery add target=“_blank” for outgoing link

后端 未结 15 1804
滥情空心
滥情空心 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:47

    This is such a brilliant site I learned so much from it :

    If you do it this way you do not need to worry about http or https (handy while developing)

    $('a[href^="http"]')
            .not('a[href*='+ location.hostname +']')
            .attr('target','_blank');
    
    

提交回复
热议问题