我的应用程序是一个浏览器窗口加载本地页面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 –