Created
January 14, 2025 21:06
-
-
Save ali-master/a800c44832bfc11d687fc3f2ed5bf75e to your computer and use it in GitHub Desktop.
Disable Right-Click Using JavaScript
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.addEventListener("contextmenu", function(event) { | |
event.preventDefault(); | |
alert("Right-click is disabled on this website!"); | |
}); | |
// Disable Right-Click for Specific Elements Only | |
document.getElementById("protected-content").addEventListener("contextmenu", function(event) { | |
event.preventDefault(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment