I want to trigger a context menu event in jQuery on a audio element. Here is the code:
$("audio").contextmenu();
However, this does not show a context menu for the element. I thought maybe there is need for some user interaction so I wrapped it in a moueenter
event.
$("audio").on("mouseenter", function(e) {
$(this).contextmenu();
}
However, the context menu still does not appear. Finally, I decided to do the right click on the audio element manually and trigger a key press event but it also did not seem to do anything.
$("audio").on("contextmenu", function(e) {
var code = 86;
$(this).trigger(
jQuery.Event( 'keydown', { keyCode: code, which: code } )
);
});
This code snippet was supposed to trigger a jQuery keypress event with "v" pressed.
When we right click on an audio element and press "v", it shows a save audio as dialog. I wanted to write the code to trigger the context menu and keypress programatically but none of them seem to have any effect. Why is that?