0

处理脚本以定位外部站点 URL 并提供类以触发对话。需要排除(白名单)某些 HREF。mailto 和 tel 以及内部 URL 的异常工作正常,但尝试添加特定 URL 名称不起作用。有什么建议么?有没有更好的方法?

jQuery(document).ready(function ($) {

$.expr[":"].external = function (a) {
    return !a.href.match(/^mailto\:/) && !a.href.match(/^tel\:/) && !a.href.match(/http\/\/\:\mail\.google\.com/) && a.hostname != location.hostname
};
$("a:external").addClass("ext_link");

});

4

1 回答 1

1

也许

return !/^(mailto|tel):|http:\/\/mail\.google\.com/.test(a.href) &&
    a.hostname != location.hostname
于 2013-03-29T12:06:13.060 回答