Which one of these is the most effective vs checking if the user agent is accessing via the correct domain.
(在检查用户代理是否通过正确的域访问时,哪一项最有效。)
We would like to show a small js based 'top bar' style warning if they are accessing the domain using some sort of web proxy (as it tends to break the js).
(如果他们使用某种Web代理访问域名(因为它倾向于打破js),我们希望显示一个基于小js的“顶栏”样式警告。)
We were thinking about using the following:
(我们考虑使用以下内容:)
var r = /.*domain.com$/;
if (r.test(location.hostname)) {
// showMessage ...
}
That would take care of any subdomains we ever use.
(这将照顾我们曾经使用的任何子域。)
Which should we use host or hostname?
(我们应该使用哪个主机名或主机名?)
In Firefox 5 and Chrome 12:
(在Firefox 5和Chrome 12中:)
console.log(location.host);
console.log(location.hostname);
.. shows the same for both.
(..两者显示相同。)
Is that because the port isn't actually in the address bar?
(是因为端口实际上不在地址栏中吗?)
W3Schools says host contains the port.
(W3Schools说主机包含端口。)
Should location.host/hostname be validated or can we be pretty certain in IE6+ and all the others it will exist?
(应该验证location.host/hostname还是我们可以在IE6 +中确定其他所有其他内容?)
ask by anonymous-one translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…