我用它来检查某人是否来自 Reddit,但它不起作用。
var ref = document.referrer;
if(ref.match("/http://(www.)?reddit.com(/)?(.*)?/gi"){
alert('You came from Reddit');
} else {
alert('No you didn\'t');
}
关于正则表达式的建议也非常受欢迎。
尝试这个:
if (ref.match(/^https?:\/\/([^\/]+\.)?reddit\.com(\/|$)/i)) {
alert("Came from reddit");
}
正则表达式:
/^ # ensure start of string
http # match 'http'
s? # 's' if it exists is okay
:\/\/ # match '://'
([^\/]+\.)? # match any non '/' chars followed by a '.' (if they exist)
reddit\.com # match 'reddit.com'
(\/|$) # match '/' or the end of the string
/i # match case-insenitive
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)