js怎么判断网页是否是百度来路打开,如果是百度打开就跳转到某个地址

js怎么判断是否是百度来路打开,如果是百度打开就跳转到某个地址。
很多网页被黑,都是这种情况,直接通过网址打开正常,通过百度点击进来就会跳转到一些乱七八糟的网站。
这是怎么实现的呢?
有两种方法
第一种:

<script>
if(navigator.userAgent.toLocaleLowerCase().indexOf("baidu") != -1){
    window.location.href = 'https://zhiboblog.com';//百度打开要跳转的地址
}
</script>

第二种:

<script>
if(document.referrer.indexOf("baidu") != -1){
  window.location.href = 'https://zhiboblog.com';//百度打开要跳转的地址
}
<script>

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: