-1

I want my website to not be right-clickable. I have tried finding out how and I found out. But I don't know how to disable it without an alert-box. I want nothing to happen when someone right clicks. I tried removing the alert from the code, but that didn't work.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

2 Answers2

1
if (document.addEventListener) {
    document.addEventListener('contextmenu', function(e) {
        e.preventDefault();
    }, false);
} else {
    document.attachEvent('oncontextmenu', function() {
        window.event.returnValue = false;
    });
}

Answer based on How to add a custom right-click menu to a webpage?

Community
  • 1
  • 1
yuriy636
  • 11,171
  • 5
  • 37
  • 42
0

If you are using jQuery this would be the way to do it:

$(document).ready(function(){
    $(document).bind("contextmenu",function(e){
        return false;
    });
});

This should work.

s1h4d0w
  • 762
  • 6
  • 27
Polaris
  • 712
  • 7
  • 21
  • I've submitted an edit telling the poster they need jQuery for this answer. As is, this solution would spout a bunch of errors. – s1h4d0w May 21 '16 at 21:23