js确定来源页然后跳转

 1 <script type="text/javascript">
 2 function Navigate() {
 3     if(document.referrer == 'http://www.44755.com/game-lists'){
 4         window.location.href = "/game-lists";
 5     }else if(document.referrer == 'http://www.44755.com/'){
 6         window.location.href = "/";
 7     }
 8     // alert(document.referrer);
 9 }
10 setInterval("Navigate()", 1000);
11 </script>    
注意:这种方式用于正常连接跳转的,若A页面是采用“location.href”这样的方式跳转的话,所获取到的值是空的,因为这种跳转方式相当于直接在地址栏输入网址,从搜藏夹直接打开该页面也是获取不到。
 
如果是来源页是js跳转过来的,上边的方法就拿不到了!所以用:
 
1 var ref = '';  
2  if (document.referrer.length > 0) {  
3   ref = document.referrer;  
4  }  
5  try {  
6   if (ref.length == 0 && opener.location.href.length > 0) {  
7    ref = opener.location.href;  
8   }  
9  } catch (e) {} 
 
原文地址:https://www.cnblogs.com/redfire/p/7701902.html