Disable mouse right click using jQuery

In this article we will learn how to disable the mouse right click using jQuery, which provides security to our HTML source code along with providing security by being copied or pasted directly into the form control.

$(function()

{

$(this).bind(contextmenu, function(e)

{

e.preventDefault();

});

});

Then, in the head section of the page, include a reference to the jQuery library file. The jQuery function and jQuery library file will look like this: 

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head id=”Head1″ runat=”server”>

<title></title>

<script src=“Jquery-1.8.0.min.js” type=“text/JavaScript”></script >

<script type=“text/JavaScript”>

$(function()

{

$(this).bind(contextmenu, function(e)

{

e.preventDefault();

alert(right click is disabled); //not recommended to give alert message

});

});

</script >

</head>

<body>

<form id=”form1″ runat=”server”>

<div>

</div>

</form>

</body>

</html>

Post a Comment

www.CodeNirvana.in

Protected by Copyscape
Copyright © Compilemode