在处理了同样的问题之后,这是我在 IE 中有效的解决方案的摘录,避免了 SCRIPT5022 错误。感谢这篇文章的帮助。
var myWindow = window.open('about:blank', 'loading...', '');
var myWindowDoc = myWindow.document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
var myWindowBody = myWindow.document.createElementNS('http://www.w3.org/1999/xhtml', 'body');
myWindow.document.open().write('<html><head></head><body><div id="targetDiv"></div></body></html>');
myWindow.document.close();
try {
myWindow.document.getElementById('targetDiv').appendChild(HTMLpayload.cloneNode(true));
} catch (e){
if (HTMLpayload.outerHTML) {
myWindow.document.getElementById('targetDiv').innerHTML = HTMLpayload.outerHTML;
} else {
console.log(e);
}
}