javascript - 在 Electron 应用程序中将本地文件加载到 iframe 中

标签 javascript html node.js electron

我正在使用 Electron 构建一个应用程序让您可以预览本地计算机上存储的 HTML5 横幅广告。

到目前为止,我已经可以选择包含所有文件的目录。

选择后,iframe 的 src 将更新到该目录。

ipcRenderer.on('selected-directory', (event, data) => {
   // update preview
   const previewer = document.getElementById('preview-section-iframe')
   previewer.src = data.filePaths + '\\html\\'
}

但是,横幅未加载,html 如下所示:

<iframe id="preview-section-iframe" title="Banner preview" width="300" height="600" src="G:\BANNERS\300x600\html\">   
</iframe>

但是,当将鼠标悬停在开发工具中的 src 上时,src 会显示:

file:///G:/_projects/_dev/_electron_apps/test/electron-quick-start/G:\BANNERS\300x600\html\

它似乎正在应用程序文件中查找源代码。有办法阻止这种情况吗?

最佳答案

您的 iframe 需要一个文件路径,您为他提供了对一个文件夹的引用。

尝试更多类似的东西 <iframe id="preview-section-iframe" title="Banner preview" width="300" height="600" src="G:\BANNERS\300x600\html\yourfile.extention"><br/> </iframe>

关于javascript - 在 Electron 应用程序中将本地文件加载到 iframe 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60228725/

相关文章:

javascript - 内部图案可变

javascript - 修复 Bootstrap 下拉菜单的行为

html - 如何解决 HTML 中自定义字体的行高问题?

javascript - 异步函数在 while 循环中不立即产生结果

javascript - 如何在快速路由的控制台中记录 500 个状态错误?

javascript - 将 CSS 规则获取到 javascript 变量中

javascript - 在 GridView 中单击按钮时调用客户端事件

javascript - Chrome 扩展程序在单击按钮时弹出一个新窗口

jquery - 将鼠标悬停在导航栏上,将透明 Logo 更改为填充 Logo

javascript - 无法将 JSON Stream 用于 JSON 对象