html - 无法在 iFrame 内加载数据
问题描述
我试图获取旧网站的 URL,但发生了错误:
Fetch API cannot load http://xyz.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://abc' is therefore not allowed access.
If an opaque response serves your needs, set the request's mode to 'no-cors'
to fetch the resource with CORS disabled.
我的代码看起来像这样
render(){
return (
<div>
<iframe src="http://localhost:8080/.../StockExchangeWidget.html" />
</div>
)
}
当我在 iFrame 之外加载它时,一切正常,但是当我尝试用 iFrame 很好地加载它时,我会遇到很多错误,但仅适用于图表数据,因为您可以看到框架和按钮已加载。
当我尝试通过 WebSocket 连接内的 url 加载 HTML 页面到 'wss://widgetdata.tradingview.com/socket.io/websocket?from=widgetembed%2F&date=2018_06_09-17_59' 失败时,我也收到了 WebSocket 错误: WebSocket 握手期间出错:意外的响应代码:403
解决方案
托管 iframe 的域需要修改其CORS 策略,以允许来自您的域的请求到达其站点。如果该页面上没有 CORS 标头,您的浏览器将不会呈现 iframe 的内容(出于安全原因)。
推荐阅读
- php - Php + Mysql,添加列并填充
- python - 如何防止添加到抽象模型中的管理器成为默认管理器?
- c# - 分块从 sql 下载 Varbinary
- flutter - 如何使库比蒂诺图标在颤动中居中?
- c# - HasRequired 和 WithOptional 不生成一对一关系
- elasticsearch - ElasticSearch中不区分大小写的搜索?
- sql - Oracle Query 列出内存中的小时数
- javascript - 获取登录用户的windows域(对于网站)
- database - 可以将 mLab 用作大型 Web 应用程序的数据库吗?
- python - 如何在 Tensorflow 中绘制精度曲线