iframe与Electron中的本地资源

Pet*_*ann 4 iframe electron

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

<!DOCTYPE html>
<html>
  <head>
    <title></title>
  </head>
  <body>
    <iframe sandbox='allow-scripts' src='frm.html'></iframe>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

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

<!DOCTYPE HTML>
<html>
<head>
    <title></title>
    <script src="foo.js"></script>
</head>
<body>
    <p>Inside iframe</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

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

Not allowed to load local resource: file:///C:/electron/app1/foo.js
Run Code Online (Sandbox Code Playgroud)

在Electron中是否可能出现这种情况?

Sha*_*ski 5

这是iframe的安全功能。这是一个有关将链接文件加载到iframe中的类似问题:在iframe中显示本地htm文件?

话虽这么说,您是否考虑过使用webview标记?http://electron.atom.io/docs/v0.30.0/api/web-view-tag/。webview标记与iframe非常相似,但是可让您更好地控制其周围的安全性。我测试了将本地文件加载到webview中的方式,就像您尝试将frm.html加载到iframe中一样,它也可以正常工作。