<script type="text/javascript">
    function CheckRootPage()
    {
        if(parent.document.getElementById("byroot")){
    //        alert("a.html是b.html的父窗体");
        }else{
    //        alert("b.html没有父窗体");
            document.write("<form name=bytimesroot id=bytimesroot action=index.html method=post style='display:none' onsubmit='return'>"); 
            document.write("<input type=hidden name=loadurl name=loadurl value='login.jsp'"); 
            document.write("</form>"); 
            window.onload = function(){document.bytimesroot.submit(); }
            //window.location.href="index.jsp?loadurl=login.jsp";
        }

    }
    CheckRootPage();
    </script>

解决方案 »

  1.   

    火狐中的document.bytimesroot得到是null,因为在火狐中document对象并不是object类型,而是object HTMLDocument.
      

  2.   

    大家可以测试我那个帖子回复的代码 是可以取到object HTMLDocument的
      

  3.   

    chinmo 你的IE版本多少 我IE6没问题啊
      

  4.   

    还有一个问题,你去掉了 method也不是个好办法他的主要原因也并非因为这个
      

  5.   

    我印象里 去掉method好像默认的就是GET提交吧
      

  6.   

    我现在没明白就是
    <script>
        function CheckRootPage()
        {
            if(parent.document.getElementById("byroot")){
        //        alert("a.html是b.html的父窗体");
            }else{
        //        alert("b.html没有父窗体");
                document.write("<form  name=bytimesroot id=bytimesroot action='http://www.baidu.com' method='get'  style='display:none' onsubmit='return'>"); 
                document.write("<input type=button  name=loadurl name=loadurl value='login.jsp'"); 
                document.write("</form>"); 
                document.bytimesroot.submit(); 
    alert(document.bytimesroot)
                //window.location.href="index.jsp?loadurl=login.jsp";
            }
        }
        window.onload = CheckRootPage;
        </script>我把hidden按钮改成button形式 他就能alert(document.bytimesroot)取到表单了
      

  7.   

    呵呵
    我也不明白测试了了下
    好像就只能是在里面加一些非hidden类型的表单就可以取到
      

  8.   

    不用hidden,改成display:none就可以了
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>    <script>
        function CheckRootPage()
        {
            if(parent.document.getElementById("byroot")){
        //        alert("a.html是b.html的父窗体");
            }else{
        //        alert("b.html没有父窗体");
                document.write("<form name=bytimesroot id=bytimesroot action=index.jsp method=post style='display:none' onsubmit='return'>"); 
                document.write("<input type=button name=loadurl name=loadurl value='login.jsp' style=''display:none"); 
                document.write("</form>"); 
                document.bytimesroot.submit(); 
                //window.location.href="index.jsp?loadurl=login.jsp";
            }
        }
        window.onload = CheckRootPage;
        </script></head><body></body>
    </html>
      

  9.   

    document.write(" <input type=hidden name=loadurl name=loadurl value='login.jsp'"); 
    这个改为 
    document.write(" <input type=hidden name=loadurl value='login.jsp'"); 
    好像就好了 真搞不懂!! 真没见过这么怪的问题 
    说名字一样造成的吗! 
    但是换了一个类型他就可以了
      

  10.   


    变通一下了.
    index.jsp?loadurl=login.jsp
    这样了.也是最简单的了.
      

  11.   

    问题解决了 
    代码如下 JScript code    <script>
        function CheckRootPage()
        {
            if(parent.document.getElementById("byroot")){
                //alert("a.html是b.html的父窗体");
            }else{
                //alert("b.html没有父窗体");
                document.write(" <form name=bytimesroot id=bytimesroot action=index.jsp method=post style='display:none' onsubmit='return'>"); 
                document.write(" <input type=hidden name=loadurl id=loadurl value='login.jsp'>"); 
                document.write(" </form>"); 
                window.onload = function(){document.bytimesroot.submit(); } 
                //window.location.href="index.jsp?loadurl=login.jsp"; 
            }
        //    if(parent.window == window ){
        //        alert("b.html没有父窗体");
        //    }else{
        //        alert("a.html是b.html的父窗体");
        //    }
        }
        CheckRootPage();
        </script>放到head区里面就ok了 
    谢谢