与判断用户代理是否通过正确的域进行访问相比,以下哪项最有效.
如果他们使用某种web代理访问域(因为它往往会 destruct js),我们想显示一个基于js的"顶栏"样式的小警告.
我们正在考虑使用以下工具:
var r = /.*domain\.com$/;
if (r.test(location.hostname)) {
// showMessage ...
}
这将照顾到我们曾经使用过的任何子域.
我们应该使用主机名还是主机名?
在Firefox 5和Chrome 12中:
console.log(location.host);
console.log(location.hostname);
…两者都是一样的.
这是因为端口实际上不在地址栏中吗?
W3Schools表示主机包含端口.
Should location.host/hostname be validated or can we be pretty certain in IE6+ and all the others it will exist?个