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 ?
Add a textarea and a send button that will be used to send messages to child window. Send the text of textarea using . postMessage(message, targetOrigin) when the button is clicked. In order send and receive JSON objects instead of a simple string, JSON.
postMessage() The window. postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.
The easiest way to access a single element in the DOM is by its unique ID. You can get an element by ID with the getElementById() method of the document object.
postMessage is generally considered very secure as long as the programmer is careful to check the origin and source of an arriving message. Acting on a message without verifying its source opens a vector for cross-site scripting attacks.
According 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With