For Developers

Disable Right Mouse Click Using JavaScript

Disable Right Mouse Click Using JavaScript:

Description:

This script will prevent the default right menu from popping up when the right mouse is clicked on the web page. Works well in IE4+ and NS4+.

To use this script, paste the following code in the <body> section of your HTML document.


Disable right click on mouse


Function to handle right click if the browser is IE

<script language="JavaScript">

var message=”Right Click is Disabled”;

function ExeForIE()
{
if (event.button==2)
{
alert(message);
return false;
}
}

</script>


Function to handle right click if the browser is FireFox

<script language=JavaScript>

var message=”Right Click is Disabled”;

function ExeForFFox(evt)
{
if (document.layersdocument.getElementById&&!document.all )
{
if (evt.which==2evt.which==3)
{
alert(message);
return false;
}
}
}

if (document.layers)
{
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = ExeForFFox;
}
else if (document.all&&!document.getElementById)
{
document.onmousedown = ExeForIE;
}

document.oncontextmenu=new Function(”alert(message);return false”)

</script>


0 comments:

Post a Comment