How to disable right-clicking #2235
-
Checklist
How did you create the site?Built from DescriptionHow can I disable right-clicking on my Jekyll Chirpy website? I added the following code to disable right-click and certain key combinations (F12 and Alt), but it isn't working. It worked while using another theme, Hydure. What could be the issue with Chirpy, and how can I fix it? Operations you have already triedHere's the code I used in <!-- https://github.com/ishithemes/disablerightclick/blob/f34528a9e1d1da64d14e3ec8a599817001fdaa01/index.html -->
<script type="text/javascript">
document.onkeydown = function (event) {
event = (event || window.event);
if (event.keyCode == 123 || event.keyCode == 18)
{
return false;
}
}
document.addEventListener('contextmenu', event => event.preventDefault());
</script> Anything else?No response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Where are you including that template? If those are the only modifications you made to the Chirpy theme, the template will just be sitting there unused. |
Beta Was this translation helpful? Give feedback.
-
You need to specify a Liquid declaration like this: {% include disablerightclick.html %} In the Since all the code you are adding is JavaScript, a cleaner approach would be to create a |
Beta Was this translation helpful? Give feedback.
-
document.onkeydown = function (event) {
event = event || window.event;
if (event.keyCode === 123 || event.keyCode === 18) {
return false;
}
};
document.addEventListener('contextmenu', (event) => event.preventDefault());
<script src="/assets/js/disablerightclick.js" defer></script> The This approach is not recommended, as it can negatively impact user experience and can be easily bypassed. |
Beta Was this translation helpful? Give feedback.
Although these properties are deprecated, they may still function in certain environments.
Here is an updated script that avoids using deprecated properties: