在IE中跨不同窗口使用Javascript对象
我需要从另一个浏览器窗口打开新的浏览器窗口,并从子窗口的父窗口访问对象。因此,当加载子窗口时,我使用opener属性从父窗口访问对象。在Firefox中工作良好,但在IE中,数组属性转换为对象 e、 g 当在IE中打开子窗口时,结果将为在IE中跨不同窗口使用Javascript对象,javascript,internet-explorer,Javascript,Internet Explorer,我需要从另一个浏览器窗口打开新的浏览器窗口,并从子窗口的父窗口访问对象。因此,当加载子窗口时,我使用opener属性从父窗口访问对象。在Firefox中工作良好,但在IE中,数组属性转换为对象 e、 g 当在IE中打开子窗口时,结果将为 data is array: true prototype: [object Array] parent data is array: false parent prototype: [object Object] Firefox的结果是 data is ar
data is array: true
prototype: [object Array]
parent data is array: false
parent prototype: [object Object]
Firefox的结果是
data is array: true
prototype: [object Array]
parent data is array: false
parent prototype: [object Array]
解决方法之一是将对象序列化为JSON,传递字符串,然后反序列化。但是,对象上的任何方法都将丢失
除了坐在那里谈论IE是web开发的祸根之外,我还能做什么呢?一种解决方法是在父窗口中将对象转换为JSON,并将字符串传递给子窗口,然后子窗口将JSON解析回对象 e、 g。 在父窗口中:
function getData() {
return JSON.stringify(data);
}
在子窗口中:
var parentData = JSON.parse(window.opener.getData());
但是,这将丢失任何对象上的任何方法。我今天遇到了类似的问题,并发现使用下划线.js的以下解决方案运行良好:
var parentData=\ u0.toArray(window.opener.data);
var parentData = JSON.parse(window.opener.getData());