jQuery add target=“_blank” for outgoing link

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

    Global function to open external links in a new window:

    $(function(){ // document ready
    
        $("a").filter(function () {
            return this.hostname && this.hostname !== location.hostname;
        }).each(function () {
            $(this).attr({
                target: "_blank",
                title: "Visit " + this.href + " (click to open in a new window)"
            });
        });
    
    });
    

提交回复
热议问题