This article describes how to dynamically generate iframe in javascript compatible with mainstream browsers. If you need it, you can refer to the following code and run it in IE8. An error occurs in IE9:
The Code is as follows:
Document. createElement ('');
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;
The 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
The Code is as follows:
Var oFrame = isIE? Document. createElement ("');
} 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;
}