The specific situation is as follows:
When the page is not fully loaded, a script event that generates IFRAME is triggered by clicking the mouse.
First, we thought about adding a script event to the trigger position after the page is fully loaded. In this way, no script event exists here before the page is fully loaded, naturally, no error is reported.
The above method is somewhat passive, so see the script for generating IFRAME.
The normal page structure is
CopyCode The Code is as follows: <body>
<Form>
........
</Form>
</Body>
The script for generating IFRAME is:Copy codeThe Code is as follows: function createiframe (){
VaR objbody = Document. getelementsbytagname ("body"). Item (0 );
VaR objiframe = Document. createelement ("iframe ");
Objbody. appendchild (objiframe );
}
Appendchild () method to add a new subnode at the end of the node's subnode list. Therefore, the DOM after the IFRAME is created is:Copy codeThe Code is as follows: <body>
<Form>
........
</Form>
<IFRAME>
........
</Iframe>
</Body>
<IFRAME> is created when <form> has not been fully loaded. Therefore, a page error occurs in IE6.
I believe that the solution has been found here: if you create <IFRAME> before <form>, there will be no problem!
Then, we need to use another method for adding elements, insertbefore ():Copy codeThe Code is as follows: function createiframe (){
VaR objbody = Document. getelementsbytagname ("body"). Item (0 );
VaR objiframe = Document. createelement ("iframe ");
Objbody. insertbefore (objiframe, document. getelementbyid ("form1"); // form1 is the form ID
}
The insertbefore () method inserts a new node at any position in the node's subnode list.
Insertbefore has two parameters that can be set. The first parameter is the same as appendchild, and the second parameter can be null. The effect is equivalent to the insertbefore () method, you can also insert a new subnode before the specified subnode.Copy codeThe Code is as follows: <body>
<IFRAME>
........
</Iframe>
<Form ID "form1">
........
</Form>
</Body>