首页 > Web开发 > 详细

js确定来源页然后跳转

时间:2017-10-20 22:54:09      阅读:299      评论:0      收藏:0      [点我收藏+]
 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) {} 

 

 

js确定来源页然后跳转

原文:http://www.cnblogs.com/redfire/p/7701902.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!