iframe跨源报错:"Blocked a frame with origin from accessing a cross-origin frame"

一、报错信息:

  “Blocked a frame with origin from accessing a cross-origin frame”

二、在stackoverflow上找到原因

Same-origin security policy

You can't access an <iframe> with Javascript, it would be a huge security flaw if you could do it. For the same-origin policy browsers block scripts trying to access a frame with a different origin.

(同源策略)

Origin is considered different if at least one of the following parts of the address isn't maintained:

<protocol>://<hostname>:<port>/path/to/page.html

Protocol(协议), hostname(主机名) and port(端口) must be the same of your domain, if you want to access a frame.

 iframe调用父页面的函数:parent.functionNme();

ps:如果报以上错误,把iframe和父页面代码都放入工程项目中在本地跑起来即可解决同源问题。

 原文链接:http://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame

原文地址:https://www.cnblogs.com/evaxtt/p/9585516.html