I have 2 iframes on a page and I am trying to pass DOM element from one iframe to another using postMessage. But chrome keep giving me error:
"DataCloneError: An object could not be cloned. "
Is there a way around this issue ?
I have 2 iframes on a page and I am trying to pass DOM element from one iframe to another using postMessage. But chrome keep giving me error:
"DataCloneError: An object could not be cloned. "
Is there a way around this issue ?
Share Improve this question edited Sep 18, 2013 at 16:43 Jags asked Sep 18, 2013 at 15:08 JagsJags 1,4661 gold badge18 silver badges33 bronze badges2 Answers
Reset to default 8According to the spec, you can't send DOM nodes and it will throw an error.
Messages can be structured objects, e.g. nested objects and arrays, can contain JavaScript values (strings, numbers, Date objects, etc), and can contain certain data objects such as File Blob, FileList, and ArrayBuffer objects.
You might try with innerHTML, which "gets or sets the HTML or XML markup contained within the element." (https://developer.mozilla/en-US/docs/Web/API/Element/innerHTML)
With innerHTML you can pass element's content as a string, and then, in the other iframe, insert that content, again with innerHTML.
In this answer there is a simple way to get the innerHTML content of a node: https://stackoverflow./a/1750860/1401341
You won't get events attached to the element, but in some cases this method could be enough.