我有一个带有 svg 标签的页面。该页面有一个名为“预览”的按钮,单击该按钮将打开一个包含图像 (svg) 的新窗口。
下面是一段在 Chrome/Firefox 中工作但在 IE 中不工作的代码(我使用的是 IE 9- IE9 标准模式)
var w = window.open();
var svg = $('#chart');
var svgPrint = svg.cloneNode(true);
svgPrint.setAttribute('xmlns','http://www.w3.org/2000/svg');
w.document.body.appendChild(svgPrint);
如有任何建议,我们将不胜感激。
谢谢。
最佳答案
IE 将阻止追加在与元素追加到的窗口上下文不同的窗口上下文中创建的任何元素。
var childWindow = window.open('somepage.html');
//will throw the exception in IE
childWindow.document.body.appendChild(document.createElement('div'));
//will not throw exception in IE
childWindow.document.body.appendChild(childWindow.document.createElement('div'));
关于javascript - appendChild 无法在 IE 中使用 window.open,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17017682/