本文主要是介绍iframe 子页面postMessage报错 Failed to execute ‘postMessage‘ on ‘DOMWindow‘,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
报错信息:
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://a.page.com') does not match the recipient window's origin ('http://b.page.com')
解决方式:在子页面使用postMessage时指定origin
例如:
const host = 'http://b.page.com'
window.parent.postMessage({data: 'test'}, host);
这篇关于iframe 子页面postMessage报错 Failed to execute ‘postMessage‘ on ‘DOMWindow‘的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!