由于webview的'new-window'事件需要在渲染进程中监听,并通过进程间通信(IPC)将事件数据发送到主进程进行处理,因此需要使用ipcRenderer(渲染进程)和ipcMain(主进程)模块。 在渲染进程中监听webview的'new-window'事件: 在渲染进程的JavaScript代码中,通过webview元素的addEventListener方法监听'new-window'事件。当事件触发...
在github上查找Issues发现,渲染进程中的webview添加事件new-window监听,捕获到webview内容打开新窗口的事件,然而并不能阻止electron打开一个新的窗口 官方文档给出的是调用 event.preventDefault() 方法,但是新版本的electron 18.1是没有办法在渲染进程中去阻止这个事件,只能放到主线程中去阻止。 letcontentTemp=null;con...
Electron version: 0.37.6 Operating system: Windows 10 In a few cases, the webview new-window event is triggered twice. I can reproduce it going to https://search.yahoo.com/search?p=any+query and clicking on one of the results. Depending ...
webview has issues being hidden using the hidden attribute or using display: none;. It can cause unusual rendering behaviour within its child browserplugin object and the web page is reloaded when the webview is un-hidden. The recommended approach is to hide the webview using visibility: hidde...
老板们突发奇想,把现有的一个管理后台系统打包成桌面端可安装应用,当时我脑海就浮现出两套方案,Electron或Flutter的Webview来打包应用,相对来说Electron熟悉点,就优先考虑了使用Electron,当然后来也使用Flutter实现了一版,效果差别不大,我们先来看看Electron是怎么实现的。
webview[0].addEventListener('context-menu', function (event) { let params = event.params; let menu = MBrowser.createMenu(params); menu.popup(remote.getCurrentWindow()); }); 使用content-menu的事件来进行处理,该事件会使用electron 创建一个menu并显示 菜单创建 createMenu(options) { const hasText ...
const webContents = webview.getWebContents(); webContents.on('new-window', (event, url) => { event.preventDefault(); webview.loadURL(url); }); }); 阻止默认行为,并在当前webview加载目标页面 P.S.有个allowpopups属性也与window.open()有关,说是默认false不允许弹窗,实际使用没发现有什么作用,...
原生window.open () 允许同步打开窗口, 因此可以方便的选择是对话框还是首选项窗口。该选项也可以设置在<webview>标签上:<webview webpreferences="nativeWindowOpen=yes"></webview> BrowserWindow的创建可通过WebContents 的new-window事件进行定制 。// main process const mainWindow = new BrowserWindow({ width:...
const mainWindow = new BrowserWindow(); // 其他窗口配置... }); 1 2 3 4 5 6 7 8 重新运行你的 Electron 应用,WebView 应该能够加载那些存在证书问题的 HTTPS 页面而不再显示白屏。 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. ...
在主进程也可以使用以下方式发送消息:mainWindow.webContents.send('saveMessage','delect',index,innerIndex) webContents从主进程向渲染进程发送消息,查看更多https://www.w3cschool.cn/electronmanual/electronmanual-web-contents.html. 以下为webContents的send()官方使用介绍 ...