
我想在总结研究过程时,将用自己的发现回答这个问题。
由于这两种方法之一都存在问题的两个浏览器均为beta版,因此我已经打开了错误报告,希望这些报告能够在其完整版本发布之前解决这些问题:
Firefox 4 Beta:https
: //bugzilla.mozilla.org/show_bug.cgi?id=615927 编辑: 在FF 4b8中修复。Internet Explorer 9 Beta:https : //connect.microsoft.com/IE/feedback/details/626473
编辑: 在IE9 RC1中已修复。
我也一直发现这个…
document.replaceChild(newDomDoc, document.documentElement);
…比这快2-10倍…
var doc = document.open("text/html");doc.write(newStringDoc);doc.close();…甚至包括构建DOM节点和构建HTML字符串所需的时间。这可能是闪烁的原因,或者可能只是DOM方法的另一个支持理由。Chrome的任何一种方法都不会闪烁。
请注意,存储返回的
document内容的细微变化可以避免Firefox 4.0b7中的错误。
另请注意,此添加的MIME类型是IE docs声称为“必需”的类型。
最后,Internet Explorer似乎在解决在交换新文档之前构建的链接标记时遇到了一些麻烦。将链接href分配回给自己似乎可以修补它。
// IE requires link repairif (document.createStyleSheet) { var head = document.documentElement.firstChild; while (head && (head.tagName||"") !== "HEAD") { head = head.nextSibling; } if (head) { var link = head.firstChild; while (link) { if ((link.tagName||"") === "link") { link.href = link.href; } link = link.nextSibling; } }}一个人可以涵盖所有基础并将它们像这样组合起来…
var doc = document;try { var newRoot = newDoc.toDOM(); doc.replaceChild(newRoot, doc.documentElement); // IE requires link repair if (doc.createStyleSheet) { var head = newRoot.firstChild; while (head && (head.tagName||"") !== "HEAD") { head = head.nextSibling; } if (head) { var link = head.firstChild; while (link) { if ((link.tagName||"") === "link") { link.href = link.href; } link = link.nextSibling; } } }} catch (ex) { doc = doc.open("text/html"); doc.write(newDoc.toString()); doc.close();}…假设您有能力像我一样选择方法。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)