在新版electron中,webview标签默认是无效的。
需要在创建窗口的时候加一个属性webviewTag,把webviewTag设置为true,这样窗口就可以支持webview标签了。
const {app,BrowserWindow} = require('electron');
function createWindow(){
win = new BrowserWindow({
width:800,
height:600,
webPreferences: {
nodeIntegration: true,
webviewTag:true
}
});
win.loadFile('index.html');
win.on('closed',()=>{
console.log('closed');
win = null;
});
}
app.allowRendererProcessReuse = true;
app.on('ready',createWindow);
app.on('window-all-closed',()=>{
console.log('window-all-closed');
if(process.platform != 'darwin'){
app.quit();
}
});
app.on('activate',()=>{
console.log('activate');
if(win == null) {
createWindow();
}
});
function createWindow(){
win = new BrowserWindow({
width:800,
height:600,
webPreferences: {
nodeIntegration: true,
webviewTag:true
}
});
win.loadFile('index.html');
win.on('closed',()=>{
console.log('closed');
win = null;
});
}
app.allowRendererProcessReuse = true;
app.on('ready',createWindow);
app.on('window-all-closed',()=>{
console.log('window-all-closed');
if(process.platform != 'darwin'){
app.quit();
}
});
app.on('activate',()=>{
console.log('activate');
if(win == null) {
createWindow();
}
});