是这样的,现有也个页面a.htm,我想得到每一个访问a.htm页面的url;
用document.referrer,在得不到值;
链接到a.htm页面的形式可能有<a href>,window.open,window.location.href....请高手帮忙,如何得到上一级url

解决方案 »

  1.   

    传地个参数就行了<a herf="a.asp?url="本来的页面"">
    在a页面中,request("url")就的到了
      

  2.   

    window.top.href
    window.top.search
      

  3.   

    父页面是指包含自己的页面吧,
    可以用parent.document.location
    或者  opener.document.location
      

  4.   

    这个得不到啊,我是用window.location.href链接过来的,<a>标签也得不到
      

  5.   

    使用xxx?fromUrl=xxx,带参数过来吧。其他的方法不太容易实现
      

  6.   

    在a.htm中有:<a href="b.htm">进入子页面</a>
    然后在b.htm中:用window.parent.document.referrer即可得到“a.htm”;但是window.parent.document.referrer只能得到<a>的url,如果用window.location.href...等其他形式链接的话就得不到值更全面的解法正在寻找,暂不结贴,如果有更好的方法,希望大家一起分享,先谢过大家了
      

  7.   

    要不 来个笨点的办法 在CS的pageload里通过 Request.UrlReferrer获取到父页面的URL 用public string P_Url 保存起来  然后在aspx页面里 var url="<%=P_Url%>";  这样就获取到了
      

  8.   

    window.location.href可以得到啊,我试验过了
      

  9.   

    我的意思是在a.htm里面用<input type="button" value="按钮" onclick="goChild();" />
    js:function goChild()
    {
        window.location.href="b.htm";
    }这样的话在b.htm页面里面用window.parent.document.referrer输出为空;
    你说的那种情况是在用a.htm?url=.....传递参数,然后在b.htm页面里面接收吧?
      

  10.   

    document.referrer正解。
    获者改成用服务器端获取
      

  11.   

    href.index页面内容:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title>新建文本文档</title>
      <meta http-equiv="content-type" content="text/html; charset=gb2312"/>
     </head> <body>
    <a href="index.html">连接过去</a>
     </body>
    </html>index.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>网站公告</title>
    <style type="text/css">
    html,body{ text-align:center;} 
    </style>
    </head>
    <body>
    <script type="text/javascript">
    <!--
    alert(document.referrer)
    //-->
    </script>
    </body>
    </html>
     就这两个文件就可以了,注意要建立一个站点。不要直接双击打开href.html,而是通过使用http://localhost/href.html的方式,来访问,然后跳转到index.html的时候,就可以获取到上一个页的路径
      

  12.   

    if(window.opener){
       alert(window.opener.location.href);
    }else if(window.parent){
       alert(window.parent.location.href);
    }else{
       alert("没有parent页面");
    }