appendChild在IE中没有使用window.open [英] appendChild not working with window.open in IE

查看:99
本文介绍了appendChild在IE中没有使用window.open的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有svg标签的页面。该页面有一个名为预览的按钮,在点击时应该打开一个带有图像的新窗口(svg)。

I have a page with an svg tag. The page has a button called "Preview" which on clicking should open a new window with the image (svg).

下面是一段在Chrome /中工作的代码Firefox但不在IE中(我使用的是IE 9-IE9标准模式)

Below is a piece of code which works in Chrome/Firefox but not in IE (I'm using IE 9- IE9 standards mode)

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);

任何建议都将受到高度赞赏。

Any suggestions would be highly appreciated.

谢谢。

推荐答案

IE将阻止在元素正在追加的窗口上下文中附加在不同窗口上下文中创建的任何元素至。

IE will block appending any element created in a different window context from the window context that the element is being appending to.

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'));

这篇关于appendChild在IE中没有使用window.open的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆