某些领域禁止访问,我不希望显示一些内容,如果访客来自domain1.com domain2.com或domain3.com与document.referrer
<script>
var refers = document.referrer;
if(refers!="domain1.com") {
// bye bye content will not be displayed if domain1.com is the refer
} else if (refers!="domain2.com"){
// bye bye content will not be displayed if domain2.com is the refer
} else if (refers!="domain3.com") {
// bye bye content will not be displayed if domain3.com is the refer
}
else {
// All other domains referrers are allowed to see the content
}
</script>
这个代码不工作的到来,另一个问题是document.referrer不抓取子域或www。必须完全按照请求的domain1.com,如果它包含www将不会被检测到。
我对这个新......请不要提出任何htaccess的重写规则
感谢
不要相信引荐,有的人禁用或覆盖它因涉及隐私。并注意JavaScript不是阻止网站的好方法,它运行客户端和不允许的客户端可以禁用它。 – Oriol
你好,我试过用PHP http://stackoverflow.com/questions/24322570/http-referer-not-working-on-javascript-src但是我所有的网页都写在html格式 –
PHP代码是如此容易放置在HTML文档中。只需将该文档重命名为.php,并将php代码放在'<?php/* PHP here * /?>' – Oriol