0

我正在使用颜色框来显示一些图像。我用来调用图像的代码是:

jQuery(".ImgPop").colorbox({
    opacity: 0.4,
    rel: 'ImgPop',
    iframe: false,
    width: '770px',
    height: '680px',
    scalePhotos: true,
    current: false
});

这工作正常并弹出我的图像,我可以在其中导航它们。

我的问题是在我调用上面代码的原始页面上,我有一个脚本可以防止使用代码右键单击图像:

$(document).ready(function(){
    jQuery("img").bind("contextmenu",function(e){
        alert('Images are Copyright of this site.');
            return false;
    });
});

此代码适用于我网站上除颜色框之外的所有内容。有什么方法可以将此脚本传递给颜色框,还是我做错了什么?

4

2 回答 2

0

试试这个:

$(document).bind("contextmenu",function(e){
      e.preventDefault()
});

或者这样做:

$('img').on('contextmenu', function(e){
    return false;
});

或者

$(document).on('mousedown', 'img', function(e){
    if(e.which === 3){
        $(this).on('contextmenu', function(e){
            e.preventDefault();
        });
    };
});
于 2013-09-13T11:35:29.943 回答
0

I found out how to do this...

This is the code I used:

// This is used to prevent right clicks on images within colorbox
jQuery(document).bind('cbox_complete', function(){ 
    jQuery("img").bind("mousedown",function(e){
        if(e.which == 3){
            alert('Images are Copyright of this site.');
            return false;
        }

    });
});

// This removes the above mousedown event so that outside of colorbox
// the prevent image notification does not show twice.
jQuery(document).bind('cbox_closed', function(){ 
    jQuery("img").unbind("mousedown");
});
于 2013-09-16T09:38:33.093 回答