Le code suivant est exécuté et transmis sous IE8, et une erreur s'est produite dans IE9: Copiez le code comme suit:
document.CreateElement ('<iframe id = "yige-org-iframe" src = "yige.org.logo.gif" style = "position: absolu; en haut: 0; gauche: 0; width: 1px; hauteur: 1px; visibilité: Hidden;"> </ iframe>');
Invite d'erreur: exception: script5022: DOM Exception: invalid_character_err (5)
Analyse des idées:
Étape 1: Compatible avec IE9, Firefox, Opera, Safari et d'autres navigateurs;
La copie de code est la suivante: var iframe = document.createElement ("iframe");
iframe.setAttribute ("id", "yui-history-iframe");
iframe.setAttribute ("src", "../../images/defaults/transparent-pixel.gif");
iframe.setAttribute ("style", "position: absolu; en haut: 0; gauche: 0; largeur: 1px; hauteur: 1px; visibilité: cachée;");
Étape 2: Compatible avec IE6-8: Puisque IE6-8 ne peut pas modifier l'attribut de nom de l'Iframe
La copie de code est la suivante:
var oframe = Isie? Document.CreateElement ("<iframe name = /" "+ this._framename +" / ">"): document.createElement ("iframe");
OFRAME.NAME = "IFRAMNAME";
Solution complète:
La copie de code est la suivante:
var isie = (document.all)? vrai: false; // Voici seulement un simple jugement sur le fait que ce soit IE. Pour un jugement détaillé du navigateur: veuillez vous référer à la détection du type de navigateur
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 = "iframename";
// =======================================================================. ==========================================================================.
fonction ajaxPost (formid, showid, waitId, showidclass, soumitbtn, rappel) {
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 handlerresult = function () {
var s = '';
var évalué = false;
showloading ('Aucun');
essayer {
s = $ (ajaxframeid) .contentwindow.document.xmlDocument.Text;
} catch (e) {
essayer {
s = $ (ajaxframeid) .contentwindow.document.documentElement.firstchild.wholeText;
} catch (e) {
essayer {
s = $ (ajaxframeid) .contentwindow.document.documentElement.firstchild.Nodevalue;
} catch (e) {
S = 'Erreur interne, ne peut pas afficher ce contenu';
}
}
}
if (s! = '' && s.indexof ('ajaxerror')! = -1) {
EvalScript (s);
évalué = true;
}
if (showIdClass) {
$ (showid) .classname = showIdClass;
if (soumitBtn) {
soumisdBtn.disabled = false;
}
}
if (! évalué && (typeof ajaxerror == 'undefined' ||! ajaxerror)) {
ajaxinnerhtml ($ (showid), s);
}
ajaxerror = null;
if ($ (formid)) $ (formid) .target = formTarget;
if (typeof rappel == 'function') {
rappel();
} autre {
eval (rappel);
}
if (! évalué) evalscript (s);
ajaxframe.loading = 0;
$ ('append_parent'). removechild (ajaxframe);
};
if (! ajaxframe) {
essayer {
ajaxframe = document.createElement ('<iframe name = "' + ajaxframeid + '" id = "' + ajaxframeid + '"> </ iframe>');
} catch (e) {
ajaxFrame = document.CreateElement ('iframe');
ajaxframe.name = ajaxframeid;
ajaxframe.id = ajaxframeid;
}
ajaxframe.style.display = 'Aucun';
ajaxframe.loading = 1;
$ ('append_parent'). APPENDCHILD (AJAXFRAME);
} else if (ajaxframe.loading) {
retourne false;
}
_Attachevent (ajaxframe, «charge», handlerresult);
showloading ();
$ (formid) .target = ajaxframeid;
$ (formid) .action + = '& inajax = 1';
$ (formid) .submit ();
retourne false;
}