reactjs - 如何将 html 文件加载到 React 中的 iframe 元素中?
问题描述
我想将本地 html 文件加载到 React 中的iframe元素中。我在这个问题上遵循了公认的答案,但它不起作用。
我项目中的文件夹结构如下:
- 源代码
- 成分
- myIframeComponent.js
- 测试HTML文件
- 索引.html
- 成分
iframe 元素如下所示:
<iframe
src="../testHTMLFiles/index.html"
height="100%"
width="100%"
frameBorder="0"
/>
我错过了什么?
解决方案
iframe src 必须包含绝对 url:
https://www.example.com/testHTMLFiles/index.html
这是因为在您的构建中,文件在构建后在此位置不可用,并且 iframe 路径在 iframe 被实例化时被解析。
推荐阅读
- javascript - 三.js定位问题和coneGeometry错误
- c - (C) 我们可以通过哪些方式来操作内存长度和地址?
- c# - InternetSetCookieEx InternetGetCookieEx Cookie 从不/总是过期
- php - Ubuntu LEMP 堆栈中的 Laravel 502 错误网关
- c++ - 如何阻止角色在控制台中移动?
- java - 一旦我运行我的 Appium 脚本,线程“主”java.lang.NoClassDefFoundError 中的异常
- javascript - 无法使用 Ace 作为 RequireJS 依赖项
- select - 触发选择选项(选项包含多个单词)
- spring-boot - 带有 jsp 视图和 Swagger-ui 的 Spring-boot Spring-MVC 应用程序
- java - 跨类共享相同的变量