I have a javascript that prevents right click on an HTML page:
document.addEventListener("contextmenu", function(e){
e.preventDefault();
}, false);
I have a <input>
tag on that same page with the name "Link" that I want the right click to happen on.
How can I achieve that?
You can check and test e.target
of the event:
document.addEventListener("contextmenu", function(e){
if (e.target.tagName.toLowerCase() === 'input' && e.target.name === 'Link') {
return; //pass
}
e.preventDefault(); // prevent others
}, false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With