Jquery/JS prevent right click menu in browsers

前端 未结 12 1718
孤城傲影
孤城傲影 2020-12-03 00:42

I have my div with a right click popup menu:

// Attatch right click event to folder for extra options
$(\'#fBox\' + folderID).mousedown(function(event) {
            


        
相关标签:
12条回答
  • 2020-12-03 00:52

    You can disable the right click by appending oncontextmenu="return false;" to your body tag.

    <body oncontextmenu="return false;">
    
    0 讨论(0)
  • 2020-12-03 00:52

    One jQuery line:

    $('[id^="fBox"]').on("contextmenu", function(evt) {evt.preventDefault();});
    
    0 讨论(0)
  • 2020-12-03 00:54

    You can disable context menu on any element you want:

    $('selector').contextmenu(function() {
        return false;
    });
    

    To disable context menu on the page completely (thanks to Ismail), use the following:

    $(document).contextmenu(function() {
        return false;
    });
    
    0 讨论(0)
  • 2020-12-03 00:55

    This is a default behavior of browsers now to disable the alternate-click override. Each user has to allow this behavior in recent browsers. For instance, I don't allow this behavior as I always want my default pop-up menu.

    0 讨论(0)
  • 2020-12-03 00:58

    Try this:

    $('#fBox' + folderID).bind("contextmenu", function () {
                    alert("Right click not allowed");
                    return false;
                });
    
    0 讨论(0)
  • 2020-12-03 00:58

    Using jQuery:

    $('[id^="fBox"]').bind("contextmenu",function(e){
        return false;
    });
    

    Or disable context menu on the whole page:

    $(document).bind("contextmenu",function(e){
        return false;
    });
    
    0 讨论(0)
提交回复
热议问题