iframe跨源報錯:"Blocked a frame with origin from accessing a cross-origin frame"

1、報錯信息:html

  「Blocked a frame with origin from accessing a cross-origin frame」dom

2、在stackoverflow上找到緣由ide

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和父頁面代碼都放入工程項目中在本地跑起來便可解決同源問題。spa

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

相關文章
相關標籤/搜索