Stringify DOMWindow对象

ggu*_*erg 8 javascript json

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

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
Run Code Online (Sandbox Code Playgroud)

在Safari和Chrome上测试过.有没有人有任何想法我怎么能做到这一点?

编辑:

将编辑移至新问题,因为它并不特定于此.

Ale*_*lex 5

你为什么要序列化DOM?如果必须,Crescent的链接是您需要查看的地方.您无法序列化(stringify)窗口对象的原因是因为它包含循环引用,并且JSON.stringify默认情况下不支持它们.