字符串化DOMWindow对象 [英] Stringify DOMWindow object

查看:72
本文介绍了字符串化DOMWindow对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我似乎无法在DOMWindow对象上使用JSON.stringify.例如:

For some reason I seem unable to use JSON.stringify on a DOMWindow object. For example:

console.log(window.self); // Outputs a hierarchical DOMWindow object
console.log(JSON.stringify(window.self)); // Outputs nothing - not even an error

alert(window.self); // Alerts "[object DOMWindow]"
alert(JSON.stringify(window.self)); // Again nothing - not even an error

在Safari和Chrome上进行了测试.有谁知道我如何实现这一目标?

Tested on Safari and Chrome. Does anyone have any ideas how I can achieve this?

修改:

已将编辑内容移至新问题,因为它并非特定于此.

Moved edit to a new question as it's not really specific to this.

推荐答案

为什么要序列化DOM?如果需要,可以在Crescent的链接中查找.无法序列化(字符串化)窗口对象的原因是因为它包含循环引用,并且JSON.stringify默认情况下不支持它们.

Why would you want to do serialize the DOM? If you must, Crescent's link is where you need to look. The reason you cannot serialize (stringify) the window object is because it contains circular references, and JSON.stringify does not support them by default.

这篇关于字符串化DOMWindow对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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