Jquery/JS prevent right click menu in browsers

前端 未结 12 1760
孤城傲影
孤城傲影 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 01:02

    Try...

    $('[id^="fBox"]').mousedown(function(event) {
        if (event.which == 3) {
            event.preventDefault();
            // Set ID
            currRClickFolder = $(this).attr('id').replace('fBox','');
    
            // Calculate position to show popup menu
            var height = $('#folderRClickMenu').height();
            var width = $('#folderRClickMenu').width();
            leftVal = event.pageX - (width / 2) + "px";
            topVal = event.pageY - (height) + "px";
            $('#folderRClickMenu').css({ left: leftVal, top: topVal }).show();
    
        }
    });
    

    if you have any dynamic creation of these boxes then...

    $('[id^="fBox"]').live('mousedown',function(event) {
        ...
    });
    

提交回复
热议问题