簡體   English   中英

基於引薦來源網址重定向

[英]Redirect based on referrer URL

在我的網站中,我有一個受密碼保護的頁面,其中包含一些鏈接,這些鏈接指向也由我自己操作且無法受密碼保護的其 我想將HTML代碼放在我操作的其他站點上,檢查到達頁面的人是否已經從“鏈接頁面”的URL引用。

(我知道這不是一個安全的選擇)

摘要:

If Referrer = 'Links Page URL' *then* Do nothing *Else* Redirect: www.google.com.

有誰知道我可以復制並粘貼到我的網站的簡單HTML / Javascript代碼?

if (document.referrer !== "http://www.stackoverflow.com") {
    window.location.href = "http://www.google.com";
}

或者您可以使用正則表達式來檢查引用者。

無論如何,這個解決方案真的非常不安全。 您可以在瀏覽器中關閉JavaScript,但不會重定向...

嘗試這個

    function url(url){
      return url.match(/:\/\/(.[^/]+)/)[1];
    }

    function check()
    {
      var ref = document.referrer;
      if(url(ref) =='www.google.com')
      {
          // do something
      }
      else
      {
         // redirect
         window.location.href = 'http://yourDomain.com';
      }
   }

我發現document.referrer對我不起作用,但是location.href有效:

if (location.href != "http://yoursite/index.html") {
    location.replace("http://yoursite/index.html");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM