RegEx创建URL白名单



正在编写一个脚本来针对外部站点的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");

});

可能

return !/^(mailto|tel):|http://mail.google.com/.test(a.href) &&
    a.hostname != location.hostname

最新更新