某些領域禁止訪問,我不希望顯示一些內容,如果訪客來自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