Last active
September 23, 2024 09:39
-
-
Save msuchodolski/41c9338f3a732379dc570142826ed76e to your computer and use it in GitHub Desktop.
Disable dragging and selecting html elements (like links, images etc...) in Electron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* MAKE ELECTRON APP FEEL MORE NATIVE | |
* | |
* * Prevent dragging all HTML elements, specially: | |
* - images | |
* - links (anchors) | |
* | |
* * Prevent text selection | |
*/ | |
*, *::after, *::before { | |
-webkit-user-select: none; | |
-webkit-user-drag: none; | |
-webkit-app-region: no-drag; | |
cursor: default; | |
} | |
Thanks!
or if you don't want to include yet another npm module, paste this into your html
<script>document.addEventListener('dragover', event => event.preventDefault());document.addEventListener('drop', event => event.preventDefault());</script>
Thank you @msuchodolski and @theLMGN!
great solution. thx
Since I do want some text-selection and different cursors, I used only:
*, *::after, *::before {
-webkit-user-drag: none;
-webkit-app-region: no-drag;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That
cursor: default;
was not so useful. All rest is aewsome. Thank you!