0

I have seen a method to disable right click, but I was wondering how do you disable it on HTML5 audio.

I have seen examples for disabling right click using a line of JS, but however it does not work on DOM.

JS:

document.addEventListener('contextaudio', event => event.preventDefault());

HTML:

   <audio controls controlslist="nodownload" name="media">
      <source
        src="test.mp3"
        type="audio/mp3"
      />
    </audio>
Code...
  • 104
  • 1
  • 11
  • Possible duplicate of [Disable Right-Clicking In HTML5 Video?](https://stackoverflow.com/questions/22992645/disable-right-clicking-in-html5-video) – EGC Oct 17 '19 at 22:45
  • No, I actually view that question before this one and the other question was not helpful. – Code... Oct 23 '19 at 01:24

1 Answers1

3

Just simply add oncontextmenu= "return false;" like this:

<audio oncontextmenu="return false;" controls controlslist="nodownload" name="media">
      <source src="cool.mp3" type="audio/mp3"/>
</audio>
Ömürcan Cengiz
  • 2,085
  • 3
  • 22
  • 28