出于某种原因,我似乎无法在 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
在 Safari 和 Chrome 上测试。有谁知道我如何实现这一点?
编辑:
将编辑移至一个新问题,因为它并不是真正针对此问题。
最佳答案
为什么要序列化 DOM?如果必须的话,Crescent 的链接是您需要查看的地方。无法序列化(字符串化)窗口对象的原因是因为它包含循环引用,JSON.stringify
默认不支持它们。
关于javascript - 字符串化 DOMWindow 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4079653/