Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  151] [ 7]  / answers: 1 / hits: 131778  / 7 Years ago, tue, february 21, 2017, 12:00:00

I'm trying to call



parent.postMessage(obj, 'whatever');


from within an iframe and I'm getting this error: Uncaught DOMException: Failed to execute 'postMessage' on 'Window': An object could not be cloned.


More From » iframe

 Answers
19

It turns out the object I passed had methods, which is why the error message said An object could not be cloned.



In order to fix this, you can do the following:



obj = JSON.parse(JSON.stringify(obj));
parent.postMessage(obj, 'whatever');

[#58831] Monday, February 20, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ronans

Total Points: 460
Total Questions: 109
Total Answers: 108

Location: Slovenia
Member since Sat, Sep 11, 2021
3 Years ago
;