javascript – appendChild在IE中不使用window.open

我有一个带有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 HTML DOM 节点


下一篇:Javascript在元素后附加子元素[复制]