次のコードが実行され、IE8の下で渡され、IE9でエラーが発生しました。次のようにコードをコピーします。
document.createElement( '<iframe id = "yige-org-iframe" src = "yige.org.logo.gif" style = "position:absolute; top:0; left:0; width:1px; height:1px; visibility:hisdibility:hidden;"> </iframe>');
エラープロンプト:例外:script5022:dom例外:invalid_character_err(5)
アイデア分析:
ステップ1:IE9、Firefox、Opera、Safari、その他のブラウザと互換性があります。
コードコピーは次のとおりです。variframe = document.createelement( "iframe");
iframe.setattribute( "id"、 "yui-history-iframe");
iframe.setattribute( "src"、 "../../images/defaults/transparent-pixel.gif");
iframe.setattribute( "style"、 "position:aspolute; top:0; left:0; width:1px; height:1px; vivivibility:hidden;");
ステップ2:IE6-8と互換性:IE6-8がIFrameの名前属性を変更できないため
コードコピーは次のとおりです。
var oframe = isie? document.createElement( "<iframe name =/" " + this._framename +"/">"):document.createelement( "iframe");
oframe.name = "iframname";
包括的なソリューション:
コードコピーは次のとおりです。
var isie =(document.all)? True:false; //これは、それがIEであるかどうかについての単純な判断にすぎません。詳細なブラウザの判断については:ブラウザのタイプの検出を参照してください
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";
// ============================================================================== ==============================================================================
関数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');
試す {
s = $(ajaxframeid).contentwindow.document.xmldocument.text;
} catch(e){
試す {
s = $(ajaxframeid).contentwindow.document.documentelement.firstchild.wholeText;
} catch(e){
試す {
s = $(ajaxframeid).contentwindow.document.documentelement.firstchild.nodevalue;
} catch(e){
s = '内部エラー、このコンテンツを表示できません';
}
}
}
if(s!= '' && s.indexof( 'ajaxerror')!= -1){
EvalScript(s);
evaled = true;
}
if(showidclass){
$(showid).classname = showidclass;
if(submintbtn){
submittedbtn.disabled = false;
}
}
if(!evaled &&(typeof ajaxerror == 'undefined' ||!ajaxerror)){
ajaxinnerhtml($(showid)、s);
}
ajaxerror = null;
if($(formid))$(formid).target = formtarget;
if(typeof recall == 'function'){
想起();
} それ以外 {
eval(recall);
}
if(!evaled)evalalscript(s);
ajaxframe.loading = 0;
$( 'append_parent')。removechild(ajaxframe);
};
if(!ajaxframe){
試す {
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')。appentchild(ajaxframe);
} else if(ajaxframe.loading){
falseを返します。
}
_attachevent(ajaxframe、 'load'、handleresult);
showloading();
$(formid).target = ajaxframeid;
$(fordid).action += '&inajax = 1';
$(fordid).submit();
falseを返します。
}