Code As follows:
Copy code The Code is as follows: var $ alertpanel =$ (document. createelement ("Div "));
Export alertpanel.css ("width", "120px" ).css ("height", "50px"). Text ("Hello cssrain! ");
Parameters ('body', parent.doc ument). append ($ alertpanel );
According to his meaning, I also wrote a demo and found that it was indeed like this.
I did not see any similar problems after turning over the information.
Then I wrote it once using the native DOM method and found that it would not work either.Copy codeThe Code is as follows: var DIV = Document. createelement ("Div ");
Div. style. width = "120px ";
Div. style. Height = "50px ";
Div. style. Border = "solid 1px #000000 ";
Div. innerhtml = "Hello cssrain! ";
Parent.doc ument. Body. appendchild (DIV );
If you want to appendchildto parent.document, what about parent.doc ument. createelement when you create the appendchildfile?
So I changed the code:Copy codeThe Code is as follows: var DIV = parent.doc ument. createelement ("Div ");
Div. style. width = "120px ";
Div. style. Height = "50px ";
Div. style. Border = "solid 1px #000000 ";
Div. innerhtml = "Hello cssrain! ";
Parent.doc ument. Body. appendchild (DIV );
In this way, IE6 and IE7 can be used successfully.
Example:
Demo address: http://demo.jb51.net/js/IE-createElement/page1.htm
Summary:
If you want to create a parent page element in IE6 and IE7, you must make the creation element belong to the parent page.Copy codeThe Code is as follows: var dummy = parent.doc ument. createelement ("Div ");
VaR T = parent.doc ument. createelement ("table ");
In Firefox and IE8, it allows you to create elements to be appended to another document in one document.
In firefoxand ie8, you can use parent.doc ument or document.
In addition, Google's browser is very weird and messy. If you want to be compatible with the Google browser, we recommend that you use the parent. Function Name () to call the parent page.