The Code is as follows:
Copy codeThe 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.