javascript - appendChild 无法在 IE 中使用 window.open

标签 javascript internet-explorer window.open appendchild

我有一个带有 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/

相关文章:

html - CSS 高度在本地打开时在 IE 中有效,而不是远程

打印 Canvas

Javascript 防止点击劫持

javascript - 在 firefox 和 opera 中打开一个带有 javascript 错误的后台窗口

javascript - 显示和隐藏 div Android 风格

javascript - 将 div 中的所有链接替换为帖子

javascript - D3 : replacing anonymous function with a named one

javascript:按字符串中给定域(子字符串)查找完整 URL 的最快方法

javascript - 在 ('load' 上)不适用于 Internet Explorer 11 中打开的弹出窗口

javascript - 窗口.打开("\\\\localhost\\");不适用于 win7(x64) ie8