C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » JavaScript »

Disable right click


Posted Date: 19 Jul 2008      Posted By: suresh      Member Level: Silver     Points: 1   Responses: 3



Hi:

I have writtern javascript code to disable Mouse right Click.it works great in all browsers except Opera.Here is my code



<html>
<head>
<body oncontextmenu="return false;">
</head>
</html>

Can any one give me a suggestion to work this code on Opera.





Responses

Author: Kumar Velu    19 Jul 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 6

Hi,

try like this

<HTML>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) {
oncontextmenu='return false';

}
}

if (document.layers) {
if (e.which == 3) {
oncontextmenu='return false';
}
}
}

if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;

function handleKeyDown() {
if (window.event.keyCode == 116) {
event.keyCode=0;
event.returnValue=false;
}
}
document.onkeydown = handleKeyDown;
</SCRIPT>

</HEAD >

<BODY BGCOLOR="#E0E0E0" TEXT="#000080" oncontextmenu="return false"
ondragstart="return false" onselectstart="return false">
U can not right click on this page
</BODY>



Author: shanmukha kumari    21 Jul 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

Simply add the following code to the <BODY> section of your web page (Press Ctrl C after selecting code to copy it):


<script language=JavaScript>
<!--

//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

var message="Function Disabled!";

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

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

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

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

// -->
</script>



Author: Senthil V    28 Jul 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

//for disabling the right click in the webpage
document.oncontextmenu=new Function("return true")

var message="Your message here";
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}

}

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

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


var omitformtags=["input", "textarea", "select"]
omitformtags=omitformtags.join("|")

function disableselect(e)
{
if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
return false
}

function reEnable()
{
return true
}

if (typeof document.onselectstart!="undefined")
document.onselectstart=new Function ("return false")
else
{
document.onmousedown=disableselect
document.onmouseup=reEnable
}



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Disable Print screen,Right Click using javascript
Previous : i am using imagebutton,when I want to change the color
Return to Discussion Forum
Post New Message
Category: JavaScript

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use