【发布时间】:2017-01-13 21:53:15
【问题描述】:
我的应用是 electron,带有 BrowserWindow 加载本地页面 index.html。
我调用 npm run start 一个脚本来运行 electron main.js ,应用程序打开并加载了 html。
我可以在脚本中添加一个参数,将不同的 html 文件加载到 BrowserWindow 中吗?
main.js 文件中的代码是:
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
webPreferences:{
webSecurity:false
},
fullscreen : false });//, alwaysOnTop : true , kiosk : true })
mainWindow.setMenu(null);
// and load the index.html of the app.
let url = `file://${__dirname}/index.html`; \\ index.html should be determined by argument passed at start.
mainWindow.loadURL(url,loadOptions);
// Open the DevTools.
mainWindow.webContents.openDevTools();
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
}
【问题讨论】:
-
process.argv没有填充吗? -
是的,但是如何传递我的参数,例如 -html=index2.html