I am making an application using atom-shell that needs to load several html pages. Each time I load a different page, I need to execute some custom script. For this I am using mainWindow.webContents.on('did-finish-load', ...)
. But since I need to have a custom function for each file, I would like to unregister from the did-finish-load event.
Example:
mainWindow.webContents.on('did-finish-load',function() {
console.log('loaded page1');
mainWindow.webContents.unregister('did-finish-load') // <= does that exist?
});
mainWindow.loadUrl('file://.../page1.html');
BrowserWindow
extends EventEmitter
, so you would remove a listener the same way you typically would in Node.js:
var handler = function () {
// ...
};
mainWindow.webContents.on('did-finish-load', handler);
// Later:
mainWindow.webContents.removeListener('did-finish-load', handler);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With