The following code runs through under IE8 and has an error in IE9:
Copy Code code as follows:
Document.createelement (' <iframe id= "Yige-org-iframe" src= "Yige.org.logo.gif" style= "position:absolute;top:0; Left:0;width:1px;height:1px;visibility:hidden; " ></iframe> ');
Error tip: Exception:SCRIPT5022:DOM Exception:invalid_character_err (5)
Thinking Analysis:
First step: Compatible with Ie9,firefox,opera,safari and other browsers;
Copy Code code as follows:
var iframe = document.createelement ("iframe");
Iframe.setattribute ("id", "yui-history-iframe");
Iframe.setattribute ("src", ". /.. /images/defaults/transparent-pixel.gif ");
Iframe.setattribute ("Style", "Position:absolute;top:0;left:0;width:1px;height:1px;visibility:hidden;");
Step Two: Compatible ie6-8: Because ie6-8 cannot modify the IFRAME's Name property
Copy Code code as follows:
var oframe = Isie? Document.createelement ("<iframe name=/" "+ This._framename +"/">"): Document.createelement ("iframe");
Oframe.name = "Iframname";
Comprehensive Solution:
Copy Code code as follows:
var Isie = (document.all)? True:false; Here is simply to determine whether it is ie, detailed browser judgment: Please refer to browser type detection
var ua = Navigator.userAgent.toLowerCase (). Match (/msie ([/d.] +)/) [1];
if (ua = = "9.0") {
Isie = false;
}
var oframe = Isie? Document.createelement ("<iframe name=/" "+ This._framename +"/">"): Document.createelement ("iframe"); o Frame.name = "Iframname";
//=========================
function Ajaxpost (Formid, Showid, Waitid, Showidclass, submitbtn, recall) {
var Waitid = typeof Waitid = = ' undefined ' | | Waitid = = null? Showid: (Waitid!== '? Waitid: ');
var showidclass =!showidclass? ': Showidclass;
var Ajaxframeid = ' Ajaxframe ';
var ajaxframe = $ (Ajaxframeid);
var formtarget = $ (formid). Target;
var handleresult = function () {
var s = ';
var evaled = false;
Showloading (' none ');
try {
s = $ (Ajaxframeid). ContentWindow.document.XMLDocument.text;
catch (e) {
try {
s = $ (Ajaxframeid). ContentWindow.document.documentElement.firstChild.wholeText;
catch (e) {
try {
s = $ (Ajaxframeid). ContentWindow.document.documentElement.firstChild.nodeValue;
catch (e) {
s = ' Internal error, cannot display this content ';
}
}
}
if (S!= ' && s.indexof (' Ajaxerror ')!=-1) {
Evalscript (s);
Evaled = true;
}
if (Showidclass) {
$ (showid). ClassName = Showidclass;
if (SUBMITBTN) {
submitbtn.disabled = false;
}
}
if (!evaled && (typeof ajaxerror = = ' undefined ' | | |!ajaxerror)) {
Ajaxinnerhtml ($ (SHOWID), s);
}
Ajaxerror = null;
if ($ (formid)) $ (formid). target = Formtarget;
if (typeof recall = = ' function ') {
Recall ();
} else {
eval (recall);
}
if (!evaled) evalscript (s);
ajaxframe.loading = 0;
$ (' append_parent '). RemoveChild (Ajaxframe);
};
if (!ajaxframe) {
try {
Ajaxframe = document.createelement (' <iframe name= ' + Ajaxframeid + ' "id=" ' + Ajaxframeid + ' "></iframe> ');
catch (e) {
Ajaxframe = document.createelement (' iframe ');
Ajaxframe.name = Ajaxframeid;
Ajaxframe.id = Ajaxframeid;
}
Ajaxframe.style.display = ' None ';
ajaxframe.loading = 1;
$ (' append_parent '). appendchild (Ajaxframe);
else if (ajaxframe.loading) {
return false;
}
_attachevent (ajaxframe, ' load ', handleresult);
Showloading ();
$ (formid). target = Ajaxframeid;
$ (formid). Action = ' &inajax=1 ';
$ (formid). Submit ();
return false;
}