iframe with local resource in Electron

ε祈祈猫儿з 提交于 2019-12-07 10:33:07

问题


I need to render iframe in my Electron application:

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

where the frm.html links the local file script foo.js which is part of my Electron application

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

When I run the application in Electron I can see this error in devtools console

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

Is it possible such scenario in Electron?


回答1:


This is a security feature of the iframe. Here is a similar question that talks about loading linked files into an iframe: Displaying local htm file in iframe?.

That being said, have you considered using the webview tag instead? http://electron.atom.io/docs/v0.30.0/api/web-view-tag/. The webview tag is very similar to an iframe, but gives you more ability to control the security around it. I tested loading a local file into a webview in the same way you attempt to load frm.html into the iframe and it works flawlessly.



来源:https://stackoverflow.com/questions/31810694/iframe-with-local-resource-in-electron

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!