网络编程
位置:首页>> 网络编程>> JavaScript>> javascript获取来源的URL代码

javascript获取来源的URL代码

作者:zishu 来源:zishu博客 发布时间:2009-02-25 12:36:00 

标签:JavaScript,来源,url

Javascript 正常取来源网页的URL只要用:

 document.referrer

就可以了!

但,如果来源页是Javascript跳转过来的,上边的方法就拿不到了!所以用:

 opener.location.href

所以,就有了下边的代码:

var ref = '';
 if (document.referrer.length > 0) {
  ref = document.referrer;
 }
 try {
  if (ref.length == 0 && opener.location.href.length > 0) {
   ref = opener.location.href;
  }
 } catch (e) {}

其它相关的:

window.location.href
window.location.pathname

var num = Math.round(Math.random()*10000);
window.location.href = (window.location.pathname)+'?'+num+';

 

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com