admin管理员组文章数量:1421009
I’m trying to develop an Electron application that supports a basic plugin architecture. The main.js
process loads a basically empty 'Wele' page, except for some kind of header section for title and which contains a drop-down menu listing the available plugins.
Each plugin has its own renderer.js
file, configuration data etc. It also provides the necessary HTML to display inside the div#plugin-container
. I’m hoping to have the renderer process load the HTML fragment into the existing web page inside the aforementioned div
.
I understand that the win.loadURL()
is for the main.js
only and it loads an HTML to fill in the whole window. I’m looking to load a fragment into an existing page. jQuery has the $('div#plugin-container').load()
method that would do what I need, but it’s loading HTML from a server only, as far as I can see. And I want to load it from within the Electron application.
Any ideas?
Disclosure: I posted this message previously on the Atom discussion board here, but hope to get a better response from the SO munity.
I’m trying to develop an Electron application that supports a basic plugin architecture. The main.js
process loads a basically empty 'Wele' page, except for some kind of header section for title and which contains a drop-down menu listing the available plugins.
Each plugin has its own renderer.js
file, configuration data etc. It also provides the necessary HTML to display inside the div#plugin-container
. I’m hoping to have the renderer process load the HTML fragment into the existing web page inside the aforementioned div
.
I understand that the win.loadURL()
is for the main.js
only and it loads an HTML to fill in the whole window. I’m looking to load a fragment into an existing page. jQuery has the $('div#plugin-container').load()
method that would do what I need, but it’s loading HTML from a server only, as far as I can see. And I want to load it from within the Electron application.
Any ideas?
Disclosure: I posted this message previously on the Atom discussion board here, but hope to get a better response from the SO munity.
Share Improve this question asked Mar 21, 2018 at 21:17 jfixjfix 5638 silver badges28 bronze badges 4- are you open to frameworks like react? – Rhayene Commented Mar 22, 2018 at 9:55
- @Rhayene funny you should ask that question, I had a paragraph in my initial question saying that I'd like to avoid react and similar frameworks as to not add to the stuff I have to learn. I may get there in the end though. :-) – jfix Commented Mar 23, 2018 at 18:00
- hey, how do you dynamically execute plugins' renderer.js scripts? – VIPPER Commented Aug 29, 2019 at 22:30
- @VIPPER have a look here, not sure if it answers your question: github./jfix/pac-toolkit - I haven't looked at this code for a while. – jfix Commented Aug 31, 2019 at 14:16
1 Answer
Reset to default 6Whatever way you access the HTML you can always render it in your page if you parse it as a string. If you want to read from a file you can do something like:
const fs = require('fs')
fs.readFile('path/to/thehtml.html', (err, data) => {
document.getElementById('some-element').innerHTML = data
})
If you want the user to select the file you should use Electron's dialog
API which allows you to prompt the user with a dialog for choosing a file. Or you could have an input where they can enter the text and read from there.
本文标签: javascriptLoad HTML fragments into ElectronStack Overflow
版权声明:本文标题:javascript - Load HTML fragments into Electron - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745338664a2654160.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论