jQuery add target=“_blank” for outgoing link

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

    jQuery(document).ready(function(){
        target_luar();
    });    
    function target_luar(){
        try{
            if(top.location != location) {
                jQuery("a[href^='http']")
                  .not("[href*='"+location.host+"']")
                  .attr('target','_blank');
            }
        } catch(err) { }
    }
    

    Demo : Demo jQuery External Link

提交回复
热议问题