Iframe data will not load from one subdomain, but

2019-09-20 07:07发布

问题:

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.



标签: html iframe