Uncaught DOMException: Failed to execute 'post

2019-01-17 15:46发布

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.

1条回答
小情绪 Triste *
2楼-- · 2019-01-17 16:26

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');
查看更多
登录 后发表回答