รหัสต่อไปนี้เรียกใช้และส่งผ่านภายใต้ IE8 และเกิดข้อผิดพลาดใน IE9: คัดลอกรหัสดังนี้:
document.createElement ('<iframe id = "yige-org-iframe" src = "yige.org.logo.gif" style = "ตำแหน่ง: Absolute; top: 0; ซ้าย: 0; width: 1px; ความสูง: 1px;
ข้อผิดพลาดพรอมต์: ข้อยกเว้น: script5022: ข้อยกเว้น DOM: invalid_character_err (5)
การวิเคราะห์ความคิด:
ขั้นตอนที่ 1: เข้ากันได้กับ IE9, Firefox, Opera, Safari และเบราว์เซอร์อื่น ๆ
การคัดลอกรหัสมีดังนี้: var iframe = document.createElement ("iframe");
iframe.setAttribute ("id", "yui-history-iframe");
iframe.setAttribute ("src", "../../images/defaults/transparent-pixel.gif");
iframe.setAttribute ("สไตล์", "ตำแหน่ง: สัมบูรณ์; ด้านบน: 0; ซ้าย: 0; ความกว้าง: 1px; ความสูง: 1px; การมองเห็น: ซ่อน;");
ขั้นตอนที่ 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)? จริง: เท็จ; // นี่เป็นเพียงการตัดสินอย่างง่าย ๆ ว่าเป็นเช่นนั้นคือ สำหรับการตัดสินเบราว์เซอร์โดยละเอียด: โปรดดูการตรวจจับประเภทเบราว์เซอร์
var ua = navigator.useragent.toLowerCase (). การจับคู่ (/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, เรียกคืน) {
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 = false;
การแสดง ('ไม่มี');
พยายาม {
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);
ประเมิน = true;
-
if (showidClass) {
$ (showid) .className = showidClass;
ถ้า (submitbtn) {
SUPTITTEDBTN.DISABLED = FALSE;
-
-
if (! ประเมิน && (typeof ajaxerror == 'undefined' ||! ajaxerror)) {
ajaxinnerhtml ($ (showid), s);
-
ajaxerror = null;
if ($ (formId)) $ (formId) .target = formTarget;
if (typeof dearn == 'function') {
เรียกคืน ();
} อื่น {
eval (เรียกคืน);
-
if (! ประเมิน) evalscript (s);
ajaxframe.loading = 0;
$ ('append_parent'). RemoveChild (ajaxframe);
-
ถ้า (! 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 = 'ไม่มี';
ajaxframe.loading = 1;
$ ('append_parent'). AppendChild (AjaxFrame);
} อื่นถ้า (ajaxframe.loading) {
กลับเท็จ;
-
_attachevent (ajaxframe, 'โหลด', handleresult);
Showloading ();
$ (formId) .target = ajaxFrameId;
$ (formId) .Action += '& inajax = 1';
$ (formid) .submit ();
กลับเท็จ;
-