How to disable right-click on Moodle verison 4.3.2+

How to disable right-click on Moodle verison 4.3.2+

Mārtiņš B. གིས-
Number of replies: 18
Is it possible to disable right-click on Moodle verison 4.3.2+?
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?
དཔྱ་སྙོམས་ཀྱི་སྐུགས་ཚུ།:Useful (1)
In reply to Mārtiņš B.

Re: How to disable right-click on Moodle verison 4.3.2+

Marcus Green གིས-
Core developers གི་པར Particularly helpful Moodlers གི་པར Plugin developers གི་པར Testers གི་པར
There is nothing in core Moodle and I suspect there are no 3rd party plugins. This thread may explain some of the reasons.
https://moodle.org/mod/forum/discuss.php?d=225859
In reply to Mārtiņš B.

Re: How to disable right-click on Moodle verison 4.3.2+

QST Support གིས-
Actually it is fairly easy.

Wherever in Moodle's php scripts it prints out the Header <HTML><HEAD>... , just change <HTML> to <HTML oncontextmenu="return false">.
If all of Moodle is generated, this will block the ability to right click on the whole site.

This may impede the way Moodle works, and it is not a completely secure way to stop users from  stealing images (there is an app or addon they can download to get around this) but depending on the context of your use may be sufficient. 

This is, as others have mentioned, no substitute for a lock down browser, and both Chrome and Edge provide a kiosk mode which does much the same thing as Safe Exam Browser without having to install anything.


In reply to QST Support

Re: How to disable right-click on Moodle verison 4.3.2+

Venelouis Palhano གིས-

Could you please explain more about: how to do this?
*Updated: Oh I got it!

  1. In your Moodle site, go to: Site administration > Appearance > Additional HTML.
  2. Paste: <HTML oncontextmenu="return false"> on "Within HEAD".
  3. Worked for me! Thanks!
Attachment rightclick.png
In reply to Venelouis Palhano

Re: How to disable right-click on Moodle verison 4.3.2+

Marcus Green གིས-
Core developers གི་པར Particularly helpful Moodlers གི་པར Plugin developers གི་པར Testers གི་པར
Why do you want to disable right mouse click?
In reply to Marcus Green

Re: How to disable right-click on Moodle verison 4.3.2+

Venelouis Palhano གིས-
To have a minimum of protection against video downloads, because my videos are hosted directly on Moodle. Because for me it is more practical and cheaper, I would like to host it on YouTube but I don't know how to prevent students from clicking on the video and leaving Moodle. And on Google Drive it seemed to me that the videos were very slow (don't you think?). Could you give me your opinion on all this? Do you have a better (and not expensive) solution for students to watch videos with a great experience without leaving Moodle and not being able to easily download the videos? It would be wonderful to know.I know that there may be JavaScript scripts to prevent students from clicking on videos hosted on YouTube but I don't know what they are and I don't know how to put them in Moodle. Anyway, that's it.
In reply to Venelouis Palhano

Re: How to disable right-click on Moodle verison 4.3.2+

Marcus Green གིས-
Core developers གི་པར Particularly helpful Moodlers གི་པར Plugin developers གི་པར Testers གི་པར
Did you read this?
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.
In reply to Venelouis Palhano

Re: How to disable right-click on Moodle verison 4.3.2+

Rick Jerz གིས-
Particularly helpful Moodlers གི་པར Testers གི་པར

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?

In reply to Rick Jerz

Re: How to disable right-click on Moodle verison 4.3.2+

Venelouis Palhano གིས-
Almost. The phrase: "You do not want students to leave Moodle." is right. The rest of your text is wrong. Please answer me a few questions: where do you host your course videos? On Moodle or on another platform? Don't you care if your students download your video lessons?
In reply to Venelouis Palhano

Re: How to disable right-click on Moodle verison 4.3.2+

Rick Jerz གིས-
Particularly helpful Moodlers གི་པར Testers གི་པར
Okay, Venelous, my point (of course 😀) was to illustrate that students are always leaving Moodle to learn.  With modern computers and technology, you cannot prevent students from downloading things, including videos.
 
To answer your questions about video, I host my videos on Vimeo.  It's not free, but I find it very affordable ($20/USD per month), it has great features, and it always works.  It supports all the common features, and includes "chapters." Below, I am providing two examples of how to link to a video on Vimeo.  The first method is to use a hyperlink to the video, the second method is to embed the video.  I use both methods, depending on what I am seeking.  This particular video is what I require students to watch to learn how to use my Moodle. (Make sure to try the chapters icon in the video's control area.)
 
As a side benefit of hosting videos not on my Moodle, I can easily provide students with a link (such as in an email, saying, "You need to watch this video!"), and they do not need to be logged into Moodle.
 
Yes, I allow students to download my videos.  My philosophy is that since I cannot prevent students from copying them, I might as well make it easy to download.  Then students might watch my videos instead of some other instructor's videos, an instructor that tries not to allow downloading.  (I want students to spend time in my course, not others. 😓)
 
Vimeo does have some privacy settings that can make downloading "harder."  There is a switch to not allow downloading.  You can make a video viewable from only certain domains. You can even password protect each video (How' that for making things harder for students... that they would have to have passwords for both Moodle and videos!)
 
Incidentally, most of my course content is not in Moodle, either.  Most content is on my website.  Yes, some people would not want to do this, but this is my style.  It provides much more flexibility, ease, and power in managing content.
 
I gave a presentation at a Moodlemoot explaining my methods.
 
Here are my examples:
 
Moodle4 Overview (as a hyperlink)
 
Embedded
 
 
In reply to Rick Jerz

Re: How to disable right-click on Moodle verison 4.3.2+

Venelouis Palhano གིས-
Thank you very much for your answers. But in the end each professional has his own style right? $20/USD per month is not "very affordable" for me, but I recognize the quality of the vimeo services, I know some people who uses it, but I also know some plataforms which use some scripts to difficult the downloading or recording the videos, I just would like to know if some those scripts are simlpe and possible to put in moodle and how. If you know this would be very helpful and I think this would make some people save some money and know more about technologies, how to implement useful code, know more about moodle possibilities and capabilities and etc.
In reply to Venelouis Palhano

Re: How to disable right-click on Moodle verison 4.3.2+

Rick Jerz གིས-
Particularly helpful Moodlers གི་པར Testers གི་པར
Certainly, "cost" is dependent on the person.  And so is quality.  My university never supported my methods, not even Moodle or my hosting service, so I paid for everything with my own funds.  However, I end up with quality instruction that cannot be matched by the other instructors.
 
I assume your goal is for a student to play the video, right?

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.
In reply to Rick Jerz

Re: How to disable right-click on Moodle verison 4.3.2+

Venelouis Palhano གིས-
I think there is no problem to record for personal use, the problem is when people share what shouldn't be shared right? If I would like to freely share the content I would choose YouTube.
In reply to Venelouis Palhano

Re: How to disable right-click on Moodle verison 4.3.2+

Rick Jerz གིས-
Particularly helpful Moodlers གི་པར Testers གི་པར
If you use YouTube, I believe you are giving YouTube the rights to your videos, and YouTube can do anything they wish with your videos. That's why YouTube is free. This is not so with Vimeo (and perhaps other platforms).

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.)
In reply to Rick Jerz

Re: How to disable right-click on Moodle verison 4.3.2+

Venelouis Palhano གིས-
All right, till the moment I dont have many big videos, and I try to reduce them so it seens Hostinger interesting intermediate plan can handle this very well
In reply to Venelouis Palhano

Re: How to disable right-click on Moodle verison 4.3.2+

Bob Gilmore གིས-
Particularly helpful Moodlers གི་པར

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.

In reply to QST Support

Odp: Re: How to disable right-click on Moodle verison 4.3.2+

Pawel Alabi གིས-

For 4.5 version, it's working too. Thanks QST Support.