this is my current project structure:
main.js
index.html
download.html
src/index.js
src/style.css
main.js
will create a BrowserWindow and load index.html
, which loads index.js
and style.css
.
I'd like to create a new modal window and load download.html
when a button is clicked in index.html
.
here is codes from my index.js
:
btn.onclick = function() {
let win = new remote.BrowserWindow({
parent: remote.getCurrentWindow(),
modal: true
})
win.loadURL(`file://${__dirname}/download.html`)
}
but it's loading file://download.html
, isn't __dirname
existed in render process?
Answer: Use the Bootstrap . modal('show') method modal('show') method for launching the modal window automatically when page load without clicking anything. A common example of this technique is loading the modal when user landed on the home page and requesting them to subscribe the website newsletter.
A modal is a dialog box/popup window that is displayed on top of the current page: Open Modal.
Windows can be created from the renderer in two ways: clicking on links or submitting forms adorned with target=_blank. JavaScript calling window. open()
Just tested this code (below) and it works. Directory structure is:
main.js
app (directory)
--- index.html
--- app.js (where the code below exists)
--- modal.html
How are you accessing remote
?
"use strict";
const { remote } = require('electron');
function openModal() {
let win = new remote.BrowserWindow({
parent: remote.getCurrentWindow(),
modal: true
})
var theUrl = 'file://' + __dirname + '/modal.html'
console.log('url', theUrl);
win.loadURL(theUrl);
}
Using __dirname
will give the directory of the current file. In the main process it will be according to the filesystem. In a renderer process it will be in the context of the browser and be based on the accessed uri.
You likely want to use app.getAppPath
or app.getPath(name)
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With