- Хроники. - -

Проблема innerHTML в IE8 или фиксим руки «изобретателей стандартов».

Posted By Ikutsin On 18 декабря 2009 @ 13:30 In HTML, AJAX, JS & CSS | Comments Disabled

Я уже рассказывал о загадках IE8. Сегодня столкнулся с еще одной — innerHTML как и его братья outerHTML и insertAdjacentHTML(where, html) выдают «Unknown runtime error«. Смею заметить, что ошибка крайне информативая, в стиле IE8, так сказать.

Баз прелюдий скажу, нашел я обход для этого дела на блоге Jon Fox [1]. Для меня этот прием сработал. А именно, я поменял следующий JavaScript:

function includeContentCallback(req, status, data) {
if (req.readyState == 4) {

document.getElementById(data).innerHTML = axCleanSpaces(req.responseText);
}
}
function includeContent(divId, url) {
var req = new xHttpRequest(); //X-browser class
var ret = req.send('GET', url, null, null, null, false, divId, includeContentCallback);
}

На:

function replace_html(el, html) {
if (el) {
var oldEl = (typeof el === "string" ? document.getElementById(el) : el);
var newEl = document.createElement(oldEl.nodeName);

// Preserve any properties we care about (id and class in this example)
newEl.id = oldEl.id;
newEl.className = oldEl.className;

//set the new HTML and insert back into the DOM
newEl.innerHTML = html;
if (oldEl.parentNode)
oldEl.parentNode.replaceChild(newEl, oldEl);
else
oldEl.innerHTML = html;

//return a reference to the new element in case we need it
return newEl;
}
};
function includeContentCallback(req, status, data) {
if (req.readyState == 4) {
replace_html(document.getElementById(data), req.responseText);
}
}
function includeContent(divId, url) {
var req = new xHttpRequest();
var ret = req.send('GET', url, null, null, null, false, divId, includeContentCallback);
}

Если есть возможнось использовать Prototype или JQuery. В отличие от Moo, они тоже сделают все правильно.


Article printed from Хроники.:

URL to article: /1198-problema-innerhtml-v-ie8-ili-fiksim-ruki-izobretatelej-standartov

URLs in this post:

[1] Jon Fox: http://jonefox.com/blog/2009/05/21/internet-explorer-and-the-innerhtml-property/

Copyright © 2008 Все, что меня окружает. All rights reserved.