我有这个简单的功能
setTimeout(function() {
$('.playthis').trigger('click');
},10);
在我的网站内,导航是使用 Ajax 进行的,只有当用户来自外部而不是来自 Ajax 时,我才需要触发此功能。可能吗?
我试过了
var ref = document.referrer;
if (ref.match(/^https?:\/\/([^\/]+\.)?example\.com(\/|$)/i)) {
//nothing
} else {
setTimeout(function() {
$('.playthis').trigger('click');
},10);
}
最佳答案
这是使用 location.hostname
与 document.referrer.split("/")[2] 的简短示例
注意:代码片段在 iframe 中运行,因此它会提醒外部引荐来源网址
var isExternal = document.referrer.split("/")[2] !== location.hostname;
if (isExternal) {
alert("External referrer");
}
关于javascript - 如何使用 Javascript 检测外部链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40324384/