开发者

Javascript parentNode and innerHTML do not work properly in Firefox

I have a problem when using javascript in Firefox, here is the html:

<HTML>
<BODY>  
        <TABLE align="center">  
            <TR><td><input type=button name=submit onclick="javascript:submitIt()" value="submit" align="center"></td></TR>
            <TD>
                    <TABLE>开发者_JAVA百科;     
                            <DIV STYLE="display:none position:relative;">   
                                <FORM ID="formA" NAME="formA" METHOD="post" ACTION="b.html" TARGET="_blank">
                                <INPUT TYPE="hidden" NAME=aInput VALUE="1294457296">        
                                </FORM>
                            </DIV>
                </TABLE>
            </TD>
        </TABLE></BODY></HTML>

and here's the javascript:

    <script language="Javascript">
    function submitIt()
{
    oForm = document.getElementById("formA");
    strRequest = "<HTML><BODY>" + oForm.parentNode.innerHTML + "</BODY></HTML>";
    newDoc = window.open("", "", "");
    newDoc.document.write(strRequest);  
}

Problem is when you click submit button in this html page, you'll get a new html with source:

<HTML><BODY><form id="formA" name="formA" method="post" action="b.html" target="_blank"></form>
                                <input name="aInput" value="1294457296" type="hidden">  </BODY></HTML>

but it's supposed to be

<HTML><BODY><form id="formA" name="formA" method="post" action="b.html" target="_blank">
                                <input name="aInput" value="1294457296" type="hidden"></form>   </BODY></HTML>

Could anyone please help please? it will be really appreciated. Thanks!


It's because your HTML is seriously broken, so the DOM you end up with isn't as expected due to error handling - install Firebug and have a look at the resulting DOM.

Wrapping the <form> in the missing <tr><td>...</td></tr> should give you more like the expected DOM.

Your outer <table> is also missing a <tr> around the second <td>.


parentNode and innerHTML works properly in firefox, your problem comes from your html code which is not valid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜