我有一个弹出链接,可以检测它是否是外部链接。弹出窗口能够正确检测是否存在外部链接。
该网站使用 Mura CMS,用户使用 Mura 中的一项功能在 Mura 中创建链接(单击此处)。对于创建具有外部链接的 Mura 链接的用户来说,这是一个问题,并且正在运行的逻辑无法检测到链接是内部链接还是外部链接。
以下是用于检测外部链接的逻辑:
$("a:not('.frontEndToolsModal')").on('click', function(e){
e.preventDefault();
var url = $(this).attr('href'),
host = location.host;
if (url.indexOf(host) > -1 || url.indexOf('http','https') == -1){
/* If we find the host name within the URL,
OR if we do not find http or https,
meaning it is a relative internal link.
The following statements is to not interefere with Mura CMS front end tools
*/
if(url.indexOf('/admin/?muraAction=cArch.list') == 0){
var newTab = window.open(url, '_blank');
newTab.focus();
}
else if(url.indexOf('/admin/?muraAction') == 0){
//do nothing
}else{
window.location.href = url;
}
}else {
var m = modal.open({content: "POP UP MESSAGE"});
if(m == true) {
return m;
}
}
});
我的问题是:如何检测创建的 Mura 链接是否包含内部链接或外部链接?