How to prevent Right Click option using jquery

前端 未结 12 2199
心在旅途
心在旅途 2020-12-02 11:23

Is it possible to prevent RIGHT CLICK option for IMAGES which we use in web page.

12条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 11:42

    $(document).ready(function() {
    
        $(document)[0].oncontextmenu = function() { return false; }
    
        $(document).mousedown(function(e) {
            if( e.button == 2 ) {
                alert('Sorry, this functionality is disabled!');
                return false;
            } else {
                return true;
            }
        });
    });
    

    If you want to disable it only on image click the instead of $(document).mousedown use $("#yourimage").mousedown

提交回复
热议问题