xdevel2000 xdevel2000 - 5 days ago 6
JSON Question

JSON serialize a DOM element

If I do:

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
contains an empty object not the iframe elements WHY??

Answer

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.

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

TypeError: Converting circular structure to JSON
Comments