我试图打电话
parent.postMessage(obj, 'whatever');
来自iframe的我收到此错误:Uncaught DOMException: Failed to execute 'postMessage' on 'Window': An object could not be cloned.
答案 0 :(得分:57)
事实证明我传递的对象有方法,这就是错误消息说An object could not be cloned
的原因。
要解决此问题,您可以执行以下操作:
obj = JSON.parse(JSON.stringify(obj));
parent.postMessage(obj, 'whatever');