Nhóm :
Member
Tham gia:
16-06-2010
Bài viết:
43
Lần thăm:
308

Find, select and open new window all external links with jQuery

Bạn có muốn phân biệt tất cả các links không thuộc website của mình, và mở chúng bằng 1 cửa sổ khác?

Đoạn script sau sẽ giúp bạn thực hiện điều đó:

$.expr[':'].external = function(obj){
    return !obj.href.match(/^mailto\:/)
            && (obj.hostname != location.hostname);
};

// Add 'external' CSS class to all external links

$(function())
{
    $('a:external').addClass('external').attr('target','_blank');
}