Iframe data will not load from one subdomain, but works fine from another subdomain

青春壹個敷衍的年華 提交于 2019-12-13 06:44:40

问题


I'm trying to figure out why iframe will not load on a specific page.

Code that I'm using:

<iframe src="http://example.mywebsite.com" width="100%" height="100%" frameborder="0" ></iframe>

I'm loading it from http://frameloader.mywebsite.com

Somehow if I'm trying the same thing from http://temploader.mywebsite.com it works fine.

I've tried reloading/flushing cookies/using another browser/computer, but in all instances, it works for temploader but not for frameloader.

Does anybody have any idea why this might not work? I've been wrecking my brain and internet for days on this.


回答1:


Same Origin Policy applies to:

  1. Protocol (ex. https://)

  2. Sub-domain (ex. https://frameloader)

  3. Domain (ex. https://frameloader.mywebsite.com)

  4. Port (ex. https://frameloader.mywebsite.com:80)

All of the above must match in order to comply with Same Origin Policy. Fortunately there is a workaround for your circumstances. Add the following to both locations:

document.domain = 'mywebsite.com'

Read Iframe cross domain JavaScript calls and The document.domain exception for details.



来源:https://stackoverflow.com/questions/35917543/iframe-data-will-not-load-from-one-subdomain-but-works-fine-from-another-subdom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!