限制导航及窗口打开

pull/225/head
lyswhut 2020-03-29 14:48:02 +08:00
parent 9b536f8dc1
commit f01e367785
1 changed files with 13 additions and 1 deletions

View File

@ -1,4 +1,4 @@
const { app, BrowserWindow, Menu } = require('electron')
const { app, BrowserWindow, Menu, shell } = require('electron')
const path = require('path')
// 单例应用程序
@ -15,6 +15,18 @@ app.on('second-instance', (event, argv, cwd) => {
}
})
app.on('web-contents-created', (event, contents) => {
contents.on('will-navigate', (event, navigationUrl) => {
event.preventDefault()
})
contents.on('new-window', async(event, navigationUrl) => {
event.preventDefault()
if (/^devtools/.test(navigationUrl)) return
console.log(navigationUrl)
await shell.openExternal(navigationUrl)
})
})
const isDev = process.env.NODE_ENV !== 'production'
// https://github.com/electron/electron/issues/18397