O código a seguir é executado e aprovado no IE8, e ocorreu um erro no IE9: copie o código da seguinte forma:
document.createElement ('<iframe id = "yige-org-iframe" src = "yige.org.logo.gif" style = "position: absoluto; top: 0; esquerda: 0; largura: 1px; altura: 1px; visibilidade: hidden;"> </ifram>');
Prompt de erro: Exceção: Script5022: DOM Exceção: invalid_character_err (5)
Análise de ideias:
Etapa 1: Compatível com IE9, Firefox, Opera, Safari e outros navegadores;
A cópia do código é a seguinte: var iframe = document.createElement ("iframe");
iframe.setAttribute ("id", "yui-history-iframe");
iframe.setAttribute ("src", "../../images/defaults/transparent-pixel.gif");
iframe.setAttribute ("estilo", "posição: absoluto; topo: 0; esquerda: 0; largura: 1px; altura: 1px; visibilidade: hidden;");
Etapa 2: Compatível com o IE6-8: Como o IE6-8 não pode modificar o atributo de nome do iframe
A cópia do código é a seguinte:
var ofRame = ISIE? document.createElement ("<iframe name =/" " + this._framename +"/">"): document.createElement ("iframe");
OFRAME.NAME = "IFRAMNAME";
Solução abrangente:
A cópia do código é a seguinte:
var isie = (document.all)? Verdadeiro: falso; // Aqui está apenas um julgamento simples sobre se é IE. Para julgamento detalhado do navegador: Consulte a detecção do tipo de navegador
var ua = navegator.UserAgent.TolowerCase (). Match (/msie ([/d.] +)/) [1];
if (ua == "9.0") {
isie = false;
}
var ofRame = ISIE? document.createElement ("<iframe name = /" " + this._framename +" / ">"): document.createElement ("iframe"); de ofram.name = "iframename";
// ============================================================== ==================================================================
função ajaxpost (formid, showid, waitid, showidclass, submidbtn, recall) {
var waitid = typeof waitId == 'indefinido' || espera === NULL? SHOWID: (WaitId! == ''? WaitId: '');
var showIdClass =! ShowIdClass? '': showidclass;
var ajaxFrameId = 'AjaxFrame';
var ajaxFrame = $ (ajaxFrameId);
var formtarget = $ (formid) .Target;
var handleResult = function () {
var s = '';
var avaliado = false;
ShowLoading ('nenhum');
tentar {
s = $ (ajaxframeId) .contentWindow.document.xmldocument.text;
} catch (e) {
tentar {
s = $ (ajaxframeId) .contentWindow.document.documentElement.firstchild.wholetext;
} catch (e) {
tentar {
s = $ (ajaxframeId) .contentWindow.document.documentElement.firstchild.nodEvalue;
} catch (e) {
s = 'erro interno, não pode exibir este conteúdo';
}
}
}
if (s! = '' && s.Indexof ('ajaxerror')! = -1) {
EvalScript (s);
avaliado = true;
}
if (showidclass) {
$ (showid) .className = showIdClass;
if (submitbtn) {
submetbtbtn.disabled = false;
}
}
if (! avaliado && (typeof ajaxerror == 'indefinido' ||! ajaxerror)) {
ajaxinnerhtml ($ (showId), s);
}
Ajaxerror = nulo;
if ($ (formid)) $ (formid) .Target = formtarget;
if (typeof recall == 'function') {
lembrar();
} outro {
avaliar (recall);
}
if (! Avaliado) EvalScript (s);
ajaxframe.loading = 0;
$ ('Append_Parent'). RemoveChild (AjaxFrame);
};
if (! Ajaxframe) {
tentar {
ajaxframe = document.createElement ('<iframe name = "' + ajaxframeId + '" id = "' + ajaxframeId + '"> </frame>');
} catch (e) {
ajaxframe = document.createElement ('iframe');
ajaxframe.name = ajaxFrameId;
ajaxframe.id = ajaxframeID;
}
ajaxframe.style.display = 'nenhum';
ajaxframe.loading = 1;
$ ('Append_Parent'). AppendChild (AjaxFrame);
} else if (ajaxframe.loading) {
retornar falso;
}
_attachevent (AjaxFrame, 'Load', HandleResult);
showLoading ();
$ (formid) .Target = AjaxFrameId;
$ (formid) .Action += '& inajax = 1';
$ (formid) .submit ();
retornar falso;
}