Javascript 正则表达式创建URL白名单?
使用脚本以外部站点URL为目标,并为触发对话框提供类。需要排除(白名单)某些HREF。mailto和tel以及内部URL的例外情况可以正常工作,但尝试添加特定的URL名称不起作用。有什么建议吗?有更好的方法吗Javascript 正则表达式创建URL白名单?,javascript,jquery,regex,Javascript,Jquery,Regex,使用脚本以外部站点URL为目标,并为触发对话框提供类。需要排除(白名单)某些HREF。mailto和tel以及内部URL的例外情况可以正常工作,但尝试添加特定的URL名称不起作用。有什么建议吗?有更好的方法吗 jQuery(document).ready(function ($) { $.expr[":"].external = function (a) { return !a.href.match(/^mailto\:/) && !a.href.match(/^tel
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
除了让你的斜杠和冒号颠倒,这似乎很好:啊。。谢谢你接电话。这确实解决了问题!谢谢你,迈克!真的很喜欢这种流线型设计!使用此解决方案运行。