例如,在1.js中,
var url="${path}/jccAction.do?hxh=jcList&pageNo="+ pageNo+"pagesize="+pagesize+"&stype=ldNumber&key=";
document.frames.iframe_oper.document.location.replace(url);
在该页面中有个<IFRAME id="iframe_oper" src="2.jsp">在2.jsp中有个2.js。
var url2="";
parent.frames.iframe_detail.document.location.replace(url);
如何在URL2=“”中取到从1.js中传来的url呢。
不用split把URL分割,组成数组,重新组合。我想问有没有更加方便和快捷的方法就可以直接取到!
各位大侠们帮帮忙,在线等!

解决方案 »

  1.   


    function getUrlPara(str,name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = str.substr(str.indexOf("\?")+1).match(reg);
        if (r!=null) return unescape(r[2]); return null;
    }
    用法: getUrlPara(location.href,"你要的属性")
      

  2.   

    某页面的 url = "http://localhost:8080/b/a.jsp?name=sa&pass=qq#test" ;
    则该页面的属性值为
    document.location.hostname = localhost // 打开页面地址的主机名
    document.location.port  = 8080  // 打开页面地址的端口号 
    document.location.pathname = b/a.jsp // 打开页面地址的路径名 
    document.location.hash = test    // 打开页面地址中“#”后面的内容 
    document.location.search = name=sa&pass=qq#test // 打开页面地址中“?”后面的内容
    document.location.href = http://localhost:8080/b/a.jsp?name=sa&pass=qq#test // 打开页面的地址
      

  3.   

    1,2楼的方法我试过,没有取到,4楼的办法,是取上个页面的URL,我是想去Js中传来的url!
    3楼的方法是获取传来的参数,然后从中获取符合要求的属性,我只想一次直接把js中传来的URL全取到。
    期待高手的另外问答
      

  4.   

    主页面中 url是全局变量的话parent.url应该能取得
    <script>
    var url ="xxx"
    </script>
    <iframe src="test.htm"></iframe>
    test.htm<script>
    window.onload=function(){
    alert(parent.url)
    }
    </script>
      

  5.   

    <html>
    <head>
    <script>
    var url='';
    window.onload=function(){
      url="aa.htm";
      document.frames.iframe_oper.document.location.replace(url);
    }
    </script>
    </head>
    <body>
    <IFRAME id="iframe_oper" src="2.htm"> 
    </body>
    </html>
    ==========================================
    aa.htm:<script>
      alert(location.href)
    </script>
      

  6.   

    或者:
    <html>
    <head>
    <script>
    window.onload=function(){
      var url="aa.htm";
      document.frames.iframe_oper.document.location.replace(url);
    }
    </script>
    </head>
    <body>
    <IFRAME id="iframe_oper" src="2.htm"> 
    </body>
    </html>
    ==========================================
    aa.htm:<script>
      alert(location.href)
    </script>
      

  7.   

    大侠,这样我在页面获取的URL是2.htm,而不是aa.htm
    我是想在2.htm中获取到aa.htm
      

  8.   

    我测试得到的是aa.htm.
    检查你的document.frames.iframe_oper.document.location.replace(url);中的url是否合法
      

  9.   

    那怎么获取?2.htm已经被document.frames.iframe_oper.document.location.replace(url)转向到了aa.htm了,你只能在aa.htm中写脚本抓父页面的url。除非你不用location.replace(url)转向,那又是另外一回事情了
      

  10.   

    可能怪我没有说清楚,按照你说的话,进入1.htm后,弹出的2.htm的地址!而我希望的是进入1.htm通过触发js中的document.frames.iframe_oper到2.htm。然后在2.htm中定义个URL,该URL和1.htm中的URL保持一致,是一个动态请求。然后在2.htm中将URL传到后台处理
      

  11.   

    呵呵,我理解错了:))<html>
    <head>
    <script>
    window.onload=function(){
      var url="aa.htm";
      alert('原值:'+document.frames.iframe_oper.xsxxjsp)
      document.frames.iframe_oper.xsxxjsp=url
      alert('新值:'+document.frames.iframe_oper.xsxxjsp)
      //这个时候2.htm中的xsxxjsp变量(就是url)已经变量,怎么写库就是你的事了,呵呵
    }
    </script>
    </head>
    <body>
    <IFRAME id="iframe_oper" src="2.htm"> 
    </body>
    </html>
    ==========================================
    2.htm
    <script>
      var xsxxjsp='123'
    </script>22222222222222222222222222222
      

  12.   

    2.htm
    <script>
      var xsxxjsp='123'window.setInterval('alert(xsxxjsp)',3000)//加上这个句子就清楚了
    //你也可以把alert(xsxxjsp)变成一个函数,检测xsxxjsp的变化,一旦改变就AJAX把xsxxjsp送往后台写库
    </script>
      

  13.   

    还想在请教,别嫌烦啊,呵呵!
    你这样做可以动态的取出2.htm中的值。其实正好和我需要的相反了。我是想在2.htm中能够获得1.htm中的URL,因为正如题目中我举得例子一样,在1.htm中url是可以动态变化的,不管1中URL的如何变化在2中都能取到1中的URL,也许你会说把它反过来就行了。但是页面是已经做好了的,是在1.htm中<IFRAME src=2.htm>.然后在2.htm中取1中的URL。在帮帮忙!
      

  14.   

    那更简单了,LOOK:
    <html>
    <head>
    <script>
    var url='';
    function SetURL(){
      url="aa.htm";
    }
    SetURL()
    </script>
    </head>
    <body>
    <IFRAME id="iframe_oper" src="2.htm"> 
    </body>
    </html>
    ==========================================2.htm:
    <script> 
    var myid=0;
    function GetParentURL(){
      var xsxxjsp=parent.url;
      alert(xsxxjsp);
      //下面AJAX把xsxxjsp送往后台写库
      window.clearInterval(myid)
     // AJAX...........  //在AJAX的回调函数里,再回复myid=window.setInterval('GetParentURL()',3000)
      //....................
    }
    window.onload=function(){
      myid=window.setInterval('GetParentURL()',3000)
    }
    </script>2222222222222