0

有没有办法使用“引用 URL”,当检测到引用网站(例如来自 example.com)时,目标登录页面会隐藏页面<div class="helloworld"></div>上显示的内容?

   $(document).ready(function() {  
        if(document.referrer.indexOf(window.location.hostname) == "example.com"){  
                var referrer =  document.referrer;
                           $(".helloworld").hide();
            }
    });
<div class="helloworld">hidden when example.com is the referring URL</div>

任何关于 jquery 的帮助都可以写出来

4

1 回答 1

2

indexOf takes a string and searches for the first instance of that string inside the string in question. The result is a numeric value of the index, -1 if not found.

So your code should be something along the lines of:

$(document).ready(function() {

    var referrer =  document.referrer;
    if(!referrer) return; // no referrer

    if(referrer.toLowerCase().indexOf("example.com") !== -1){  

                       $(".helloworld").hide();
        }
})
于 2013-02-26T19:43:06.060 回答