主要代码:
//嵌入网页 let BrowserView = electron.BrowserView; let view = new BrowserView(); mainWindow.setBrowserView(view); view.setBounds({x:0,y:120,width:1000,height:680}); view.webContents.loadURL('https://www.cnblogs.com/handsomeziff/');
1、主程序代码:
1 var electron = require('electron') 2 3 var app = electron.app //引用APP 4 var BrowserWindow = electron.BrowserWindow; //窗口引用 5 var mainWindow = null; //声明要打开的主窗口 6 7 app.on('ready',()=>{ 8 mainWindow = new BrowserWindow({ 9 width:800, 10 height:800, 11 webPreferences: 12 { 13 nodeIntegration:true, 14 contextIsolation:false, 15 enableRemoteModule: true, //允许使用remote模块 16 } 17 }); 18 19 require("@electron/remote/main").initialize(); //初始化remote模块 20 require("@electron/remote/main").enable(mainWindow.webContents); // 21 22 require('./menu.js') 23 //mainWindow.loadFile('index.html'); 24 //mainWindow.loadFile('打开新窗口.html'); 25 mainWindow.loadFile('通过浏览器打开链接.html'); 26 27 //嵌入网页 28 let BrowserView = electron.BrowserView; 29 let view = new BrowserView(); 30 mainWindow.setBrowserView(view); 31 view.setBounds({x:0,y:120,width:1000,height:680}); 32 view.webContents.loadURL('https://www.cnblogs.com/handsomeziff/'); 33 34 //mainWindow.openDevTools(); 35 mainWindow.on('close',()=>{ 36 mainWindow = null; //关闭窗口释放资源 37 }) 38 });View Code
2、运行
.\node_modules\.bin\electron .
效果:
标签:嵌入,网页,BrowserView,electron,let,var,mainWindow,view From: https://www.cnblogs.com/handsomeziff/p/16969184.html