iframe数据不会从一个子域加载,但可以从另一个子域正常运行 [英] Iframe data will not load from one subdomain, but works fine from another subdomain

查看:97
本文介绍了iframe数据不会从一个子域加载,但可以从另一个子域正常运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚为什么无法在特定页面上加载iframe.

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

我正在使用的代码:

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

我正在从 http://frameloader.mywebsite.com

如果我从 http://temploader.mywebsite.com 尝试相同的操作,它将可以正常工作

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

我尝试过重新加载/刷新cookie/使用其他浏览器/计算机,但是在所有情况下,它都适用于temploader,但不适用于frameloader.

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. 协议(例如https://)

子域(例如https://frameloader)

域(例如https://frameloader.mywebsite.com)

端口(例如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'

阅读 iframe跨域JavaScript调用文档.域异常.

这篇关于iframe数据不会从一个子域加载,但可以从另一个子域正常运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆