Let's say I want to build a simple Electron app that alerts the user when he reaches example.com
Would this be possible? And if so, how would I detect if the user is viewing a certain webpage?
Electron has the did-navigate
event which is fired when a page is redirected inside a BrowserWindow
.
Referring to the above post I think,
const { BrowserWindow, dialog } = require('electron')
const win = new BrowserWindow({ width: 800, height: 600 })
win.webContents.on('did-navigate', (event, url, httpResponseCode, httpStatusText) => {
if(url == "example.com") {
dialog.showMessageBox({ type: "info", message: `You visited ${url}` });
//dialog docs at https://www.electronjs.org/docs/api/dialog#dialogshowmessageboxbrowserwindow-options
}
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.