Monday, September 14, 2009

No Right Click in a Page

JS CODE:

var BM = 2; // button middle
var BR = 3; // button right
var msg ="MOUSE RIGHT CLICK IS NOT SUPPORTED ON THIS PAGE";
function mouseDown(e)
{
try { if (event.button==BM||event.button==BR) {return false;} }
catch (e) { if (e.which == BR) {return false;} }
}
document.oncontextmenu = function() { alert(msg); return false; }
document.onmousedown = mouseDown;

BUTTONRIGHT.ASPX:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>No Right Click</title>

<script src="js/JScript.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table bgcolor="yellow">
<tr>
<td>
<img src="images/Sunset.jpg" alt="sunset" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

OR BY SIMPLE ADDING ONCONTEXTMENU IN BODY:

<body oncontextmenu="return false;">

No comments: