我正在使用 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/