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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM