我试图找到任何方法将 iframe 添加到我的 react native 应用程序中。我找到了 react-iframe ,但它对我不起作用。我跟着文件。我只是导入 react-iframe 并复制 iframe 标签以使用。我的结果如下图所示。
我需要其他方式在反应原生应用程序中使用 Iframe。谢谢你。
原文由 Mengseng Oeng 发布,翻译遵循 CC BY-SA 4.0 许可协议
我试图找到任何方法将 iframe 添加到我的 react native 应用程序中。我找到了 react-iframe ,但它对我不起作用。我跟着文件。我只是导入 react-iframe 并复制 iframe 标签以使用。我的结果如下图所示。
我需要其他方式在反应原生应用程序中使用 Iframe。谢谢你。
原文由 Mengseng Oeng 发布,翻译遵循 CC BY-SA 4.0 许可协议
尝试使用 react-native-webview
:
import { WebView } from 'react-native-webview';
....
<WebView
scalesPageToFit={true}
bounces={false}
javaScriptEnabled
style={{ height: 500, width: 300 }}
source={{
html: `
<!DOCTYPE html>
<html>
<head></head> // <--add header styles if needed
<body>
<div id="baseDiv">${iframeString}</div> //<--- add your iframe here
</body>
</html>
`,
}}
automaticallyAdjustContentInsets={false}
/>
您可以使用 iframeString
值,例如:
<iframe src="https://mdn-samples.mozilla.org/snippets/html/iframe-simple-contents.html"
title="iframe Example 1" width="400" height="300">
</iframe>
笔记:
1) 因为 source.html
参数可以是任何 html 字符串,您也可以直接传递 iframeString
而无需任何 html 页面包装器。在我的情况下,我发现使用外部 html 包装器代码自定义显示的内容更容易。
2) 关于 iframe 和 rn-webview 的已知问题:
https://github.com/react-native-webview/react-native-webview/issues?q=iframe+is%3Aopen
3) 零食链接:
https://snack.expo.dev/@florindobre99/webview-example
更多关于 webview 的信息:
https://github.com/react-native-community/react-native-webview
原文由 Florin Dobre 发布,翻译遵循 CC BY-SA 4.0 许可协议
1 回答1.6k 阅读✓ 已解决
2 回答1.2k 阅读✓ 已解决
2 回答1k 阅读✓ 已解决
2.3k 阅读
1 回答633 阅读✓ 已解决
1 回答1.9k 阅读
932 阅读
我回答我的问题。
我使用 webview 来显示 iframe。