We need basic protection for direct browser right-click saving video files from Moodle course.
There was some plugin for Moodle 3 https://moodle.org/plugins/local_disablerightclick?lang=en_us, but is there some option to do this in Moodle 4 version?
https://moodle.org/mod/forum/discuss.php?d=225859
Re: How to disable right-click on Moodle verison 4.3.2+
Could you please explain more about: how to do this?
*Updated: Oh I got it!
- In your Moodle site, go to: Site administration > Appearance > Additional HTML.
- Paste: <HTML oncontextmenu="return false"> on "Within HEAD".
- Worked for me! Thanks!

Re: How to disable right-click on Moodle verison 4.3.2+
Re: How to disable right-click on Moodle verison 4.3.2+
Re: How to disable right-click on Moodle verison 4.3.2+
https://moodle.org/mod/forum/discuss.php?d=225859
I recommend researching other discussions on this topic,on these forums as it has come up very regularly over the previous 20 years.
Re: How to disable right-click on Moodle verison 4.3.2+
Let me see if I understand what you are saying, Venelouis.
You do not want students to leave Moodle. So your courses do not have any external links to anything, such as newspapers, wikis, etc. Not a single link that takes students to another website. You do not have any PDF, Word, Excel, or Google Docs files that get opened outside of Moodle.
And to prevent students from recording videos with their smartphones, you make sure that students must be somewhere that makes it impossible for them to have their smartphones.
And maybe you are not using textbooks that students can have to learn about the topics being taught, because reading a textbook would be done outside of Moodle. Right?
Am I understanding your situation?
Re: How to disable right-click on Moodle verison 4.3.2+
Re: How to disable right-click on Moodle verison 4.3.2+
Re: How to disable right-click on Moodle verison 4.3.2+
Re: How to disable right-click on Moodle verison 4.3.2+
So what I do when I want to copy a video, I go to the video and play it. However, before playing it, I start my screen recorder software. Then I can leave my computer, do something else, and return to stop my screen recorder. It's easy to crop the beginning and end, as needed. I also add burned-in captions. Ultimately, I end up with a copy of the video that I can watch whenever I choose. Since I am the only one using this copy, I don't feel that I am at risk of violating any copyright rules.
Perhaps someone can suggest a way that they might be able to prevent me from doing what I do. I know of no way.
Re: How to disable right-click on Moodle verison 4.3.2+
Re: How to disable right-click on Moodle verison 4.3.2+
So you still have to choose: 1) do you use a paid service, or 2) do you use YouTube? No matter what you choose or try to do, students can still copy (and share if they wish) videos. This is not a Moodle problem; it's the way technology works. The only way that I know of that can prevent students from copying course materials, documents, and videos is to have them physically come to a classroom, take away their smartphones and other recording devices, and then display things to them only in this classroom.
I am unsure if I mentioned that if you upload your videos to Moodle, your Moodle backup size might increase tremendously. Can your server handle this? (Mine can't unless I pay more for hosting space.)
Re: How to disable right-click on Moodle verison 4.3.2+
Re: How to disable right-click on Moodle verison 4.3.2+
I realise this answer is old now, but you can refine it a bit. For example, if you only wanted to prevent right clicks on <video> elements.
This goes in the same Site administration > Appearance > Additional HTML. > Within HEAD as the previous solution.
<script>
window.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll(`video`).forEach( ele => ele.addEventListener('contextmenu', (e) => e.preventDefault() ) );
});
</script>
This code waits for the the web page structure ( The DOM ) to load, then grabs all <video> elements on the page and adds an event listener for them preventing the context menu from appearing, but only on that element. The context menu continues to appear elsewhere, enabling useful stuff like copy paste and context menu spell checkers to continue working everywhere else.
The querySelectorAll() method is super useful here because you can make some very complex selections. Youtube embeds for example, are in an <iframe> element, but so is H5P and I want the context menu there. However you can grab just Youtube iFrames with a wild card selector on the <iframes> src attribute.
<script>
window.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll(`video, iframe[src*="https://www.youtube.com/embed/"]`).forEach( ele => ele.addEventListener('contextmenu', evt => evt.preventDefault() ) );
});
</script>
Youtube actually overrides the context menu with its own, so good luck blocking that from within Moodle; best solution I had was to put an invisible <div> over it and block right clicking on that element instead.
Re: How to disable right-click on Moodle verison 4.3.2+
How to put this "invisible <div>" over it?
Odp: Re: How to disable right-click on Moodle verison 4.3.2+
For 4.5 version, it's working too. Thanks QST Support.