假设有一个父窗口下有两个子窗口,目前页面在其中一个子窗口下,如何操作另一个子窗口

解决方案 »

  1.   

    父窗口 中 打开时用:
    win1 = window.open(...);
    win2 = window.open(...);子窗口调用:
    opener.win2.document.XXXX
      

  2.   

    main.html<html>
    <body>
    <iframe src="sub1.html" frameborder="0"></iframe>
    <iframe src="sub2.html" frameborder="0"></iframe>
    </body>
    </html>
    sub1.html
    <html>
    <body>
    <h1>sub1</h1>
    </body>
    </html>
    sub2.html
    <html>
    <body>
    <h1>sub2</h1>
    <input id="change" type="button" value="change sub1" />
    <script>
    void function(){
    document.getElementById('change').onclick = function(){
    var iframes = parent.document.getElementsByTagName('iframe');
    for(var i = 0; iframe = iframes[i++];){
    if (/sub1\.html/.test(iframe.src)){
    var h1 = iframe.contentDocument.getElementsByTagName('h1')[0];
    if (h1) h1.innerHTML = ['sub1', +new Date];
    }
    }
    };
    }();
    </script>
    </body>
    </html>3个页面,必须同域