gpt4 book ai didi

Electron 中具有本地资源的 iframe

转载 作者:行者123 更新时间:2023-12-01 23:01:57 24 4
gpt4 key购买 nike

我需要在我的 Electron 应用程序中渲染 iframe:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<iframe sandbox='allow-scripts' src='frm.html'></iframe>
</body>
</html>

其中frm.html链接本地文件脚本foo.js,它是我的Electron应用程序的一部分

<!DOCTYPE HTML>
<html>
<head>
<title></title>
<script src="foo.js"></script>
</head>
<body>
<p>Inside iframe</p>
</body>
</html>

当我在 Electron 中运行应用程序时,我可以在 devtools 控制台中看到此错误

Not allowed to load local resource: file:///C:/electron/app1/foo.js

Electron 中可能出现这种情况吗?

最佳答案

这是 iframe 的一项安全功能。这是一个类似的问题,讨论将链接文件加载到 iframe 中:Displaying local htm file in iframe?

话虽如此,您是否考虑过使用 webview 标签? http://electron.atom.io/docs/v0.30.0/api/web-view-tag/ 。 webview 标签与 iframe 非常相似,但使您能够更好地控制其周围的安全性。我测试了将本地文件加载到 webview 中,就像尝试将 frm.html 加载到 iframe 中一样,它工作完美。

关于Electron 中具有本地资源的 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31810694/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com