JSON序列化一个DOM元素

JSON序列化一个DOM元素

问题描述:

如果我这样做:

var el =
{
   o : document.createElement("iframe")
}

var fs = JSON.stringify(el);

and then I try to access with

var ofs = JSON.parse(fs);

ofs.o 包含一个空对象而不是iframe元素为什么??

ofs.o contains an empty object not the iframe elements WHY??

JSON( JavaScript对象表示法)是不是设计用于序列化DOM节点,您需要自己提取所需的内容并将其写入对象,然后根据需要重新创建DOM节点。

JSON (JavaScript Object Notation) is not designed for serializing DOM Nodes, you'll need to pull out the stuff you want by yourself and write it to an object, and then re-create the DOM Nodes from that if you need.

事实上,Chrome甚至不执行您的代码:

In fact, Chrome doesn't even execute your code:

TypeError: Converting circular structure to JSON