I don't want a drag+drop
feature in my app since there is no need for it. So I want to completely remove the drag+drop
feature of the window. So far when dragging images the Electron window opens the image path. When dragging links the Electron window redirects to the link.
I have tried calling this:
document.addEventListener('dragstart',function(event){
event.preventDefault();
return false;
},true);
document.addEventListener('drop',function(event){
event.preventDefault();
return false;
},true);
event.preventDefault()
on the drop event
should have worked but it didn't
Also tried this:
BrowserWindow.on('will-navigate',function(event){
event.preventDefault();
return false;
});
BrowserWindow.webContents.on('will-navigate',function(event){
event.preventDefault();
return false;
});
Also failed. Any ideas how to fix this?
removeEventListener() failed as well
var listener = function (event) {
console.log('foo');
};
document.removeEventListener('drop',listener,false);
A concise version using ES6 syntax (working for me under Electron 1.4.1)
document.addEventListener('dragover', event => event.preventDefault())
document.addEventListener('drop', event => event.preventDefault())
Found a fix for Windows Electron v2.3.1 Windows Electron v0.30.0
the code should have listeners for both dragover
AND drop
.
document.addEventListener('dragover',function(event){
event.preventDefault();
return false;
},false);
document.addEventListener('drop',function(event){
event.preventDefault();
return false;
},false);
Electron will still redirect to the dropped file if you only listen to dragover
or drop
.
Cheers!
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