Prevent window navigation when dropping a link


#1

Sorry if this has been asked before, but when I drag a link from a web browser or a file into an Electron window, the window navigates to that link. Supposedly overriding the will-navigate event (described here) should prevent it, but how do I use it? The following does not seem to work, or I’m doing it wrong somehow:

mainWindow.on('will-navigate', function(event) {
    event.preventDefault();
  });

Thanks a lot in advance!


#2

The event is emitted by webContents:

mainWindow.webContents.on('will-navigate', ev => {
  ev.preventDefault()
})

#3

Worked perfectly, thank you very much!