The following code passes in IE8 and an error occurs in IE9:Copy codeThe Code is 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 message: exception: SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5)
Train of Thought Analysis:
Step 1: compatible with IE9, firefox, Opera, Safari, and other browsers;
Copy codeThe Code is 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 2: compatible with IE6-8: Since the ie6-8 cannot modify the name attribute of iframe
Copy codeThe Code is as follows:
Var oFrame = isIE? Document. createElement ("<iframe name =/" "+ this. _ FrameName +"/">"): document. createElement ("iframe ");
OFrame. name = "iframName ";
Comprehensive Solution:
Copy codeThe Code is as follows:
Var isIE = (document. all )? True: false; // you can simply judge whether the browser is IE. For more information, see 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"); oFrame. 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 = condition (formid).tar get;
Var handleResult = function (){
Var s = '';
Var evaled = false;
Showloading ('None ');
Try {
S = cipher (ajaxframeid=.content=doc ument. XMLDocument. text;
} Catch (e ){
Try {
S = certificate (ajaxframeid=.content?#document.doc umentElement. firstChild. wholeText;
} Catch (e ){
Try {
S = certificate (ajaxframeid=.content?#document.doc umentElement. firstChild. nodeValue;
} Catch (e ){
S = 'internal error, unable to 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) condition (formid).tar get = 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 ();
Authorization (formidapps.tar get = ajaxframeid;
$ (Formid). action + = '& inajax = 1 ';
$ (Formid). submit ();
Return false;
}