解决方案 »

  1.   

    跨域了,无法获得任何信息,除非两个域都能改代码,才有办法实现。
    不要求兼容的话,可以用postmessage与onmessage回调进行跨域通信;要求兼容的话用iframe方式(在子窗口中加载一个与父窗口同域的页面,变通跨域)
    当然还有最简单的,父窗口设置iframe的src时用url参数传递自身地址
      

  2.   

    怎么用url参数传递自身地址啊?
      

  3.   

    怎么用url参数传递自身地址啊?
    iframe.src="xxx.htm?parent="+location.href
      

  4.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> New Document </title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
     </head>
     <body> 
     <iframe id="frame" width="500"></iframe>
        <script type="text/javascript">
    var fatherUrl = window.location.toString();
    var childUrl = 'child.html'
    document.getElementById('frame').src = childUrl + '?url=' + encodeURIComponent(fatherUrl);
      </script>
     </body>
    </html>
    child
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> New Document </title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
      <script type="text/javascript">
    alert(document.location.toString()) // 这里获取url参数
      </script>
     </head>
     <body>  
     </body>
    </html>