Last active
October 6, 2021 08:49
-
-
Save ststeiger/be5ba12c268a8f275c1bf71e39022957 to your computer and use it in GitHub Desktop.
Prevent copy-paste and contextmenu
This file contains hidden or 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
document.oncontextmenu = function(event) | |
{ | |
event.preventDefault(); | |
event.stopPropagation(); | |
return false; | |
}; | |
document.addEventListener('contextmenu', function(event) | |
{ | |
event.preventDefault(); | |
event.stopPropagation(); | |
return false; | |
}); | |
document.onkeydown = function(event) | |
{ | |
event.preventDefault(); | |
event.stopPropagation(); | |
return false; | |
}); | |
document.addEventListener("keydown", function(event) | |
{ | |
event.preventDefault(); | |
event.stopPropagation(); | |
return false; | |
}); | |
https://developer.mozilla.org/en-US/docs/Web/API/Document/selectstart_event | |
// addEventListener version | |
document.addEventListener('selectstart', function(event) | |
{ | |
event.preventDefault(); | |
event.stopPropagation(); | |
return false; | |
}); | |
// onselectstart version | |
document.onselectstart = function(event) | |
{ | |
event.preventDefault(); | |
event.stopPropagation(); | |
return false; | |
}; | |
// https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events | |
// https://developer.mozilla.org/en-US/docs/Web/API/Event/returnValue | |
// https://stackoverflow.com/questions/5963669/whats-the-difference-between-event-stoppropagation-and-event-preventdefault | |
// stopPropagation stops the event from bubbling up the event chain. | |
// preventDefault prevents the default action the browser makes on that event. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment