Diabling Right Click option in a browser using Javascript

By: Guru Singh Emailed: 1599 times Printed: 2045 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

There are two ways you can disable the 'Right Click' option on a browser's window. These get placed in the <HEAD> of your web page.

First, the easy one:

<SCRIPT>
function click()
{
if (event.button==2)
    {   
        alert('Your Warning Message Line 1 here\nYour Warning Message Line 2 here\nYour Warning Message Line 3 here\nYour Warning Message Line 4 here');
    }
}document.onmousedown=click
// - ->
</SCRIPT>

Now, the longer one:

This script works in Internet Explorer and Netscape 6: 

<SCRIPT LANGUAGE="JavaScript1.1">
<!-- Begin
function right(e) {
var msg = "Right-clicking is not possible in this document.";
if (navigator.appName == 'Netscape' && e.which == 3) {
alert(msg); 
return false;
}
else
if (navigator.appName == 'Microsoft Internet Explorer' &&
event.button==2) {
alert(msg); 
return false;
}
return true;
}
document.onmousedown = right;
// End -->
</SCRIPT> 

Users will still be able to view the source from the browser menu (though not many will be persistent enough to figure that out), but you can sort of hide your source code there too. Just start your page with a couple of screens of blank lines and hide the code below the visible window. That will fool most people, especially if you include some bogus code right at the top: 

<phtml/unlock code=retrieve:"secure-bin/B23"; print=doc:"B23"> 

This is total nonsense, but if you tried to view the source code and only saw that, with nothing but white screen beneath it, wouldn't you be fooled? 


Javascript Home | All Javascript Tutorials | Latest Javascript Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Guru Singh
Scrolling message on the status bar using Javascript
Diabling Right Click option in a browser using Javascript
Password protect a web page using Javascript
Using revealTrans to do page transitions in Javascript
Question: How is the MVC design pattern used in Struts framework?
Question: What is the directory structure of a web application?
Question: Explain the life-cycle methods in JSP?
Question: What is an output comment in JSP?
Question: What is a Hidden Comment in JSP?
Question: What is an Expression tag in JSP?
Question: Difference between forward and sendRedirect in JSP?

More Tutorials in Javascript
Use WinSCP to transfer log files remotely using Javascript
Verifying user input in JavaScript
Pause execution in JavaScript
Javascript to display client date and time on webpage
Getting Browser's height and width using Javascript
Highlighting text on a page using CSS
Using revealTrans to do page transitions in Javascript
Password protect a web page using Javascript
Diabling Right Click option in a browser using Javascript
Scrolling message on the status bar using Javascript
window.frames[i] in Javascript
Form validation using Javascript
Using && in Javascript
The if statement in Javascript
do-while, while, for and for-in loops in Javascript

More Latest News
Most Viewed Articles (in Javascript )
Typecasting in Javascript
Diabling Right Click option in a browser using Javascript
Verifying user input in JavaScript
Pause execution in JavaScript
Use WinSCP to transfer log files remotely using Javascript
Show how many characters remaining in a html text box using javascript
Click to remove an element from a select html form using javascript
History and evolution of Javascript
Javascript Basics
List of Keywords and reverved words in Javascript
Using toString() in JavaScript to convert data types to String
Using parseInt() and parseFloat() in JavaScript to convert data types to Numbers
Bitwise NOT, AND, OR, XOR operators in Javascript
Using ! and !! in Javascript
Using && in Javascript
Most Emailed Articles (in Javascript)
Javascript Basics
Using ! and !! in Javascript
switch in Javascript
this keyword sample in Javascript
window.frames[i] in Javascript
Scrolling message on the status bar using Javascript
Javascript to display client date and time on webpage
Verifying user input in JavaScript
Show how many characters remaining in a html text box using javascript
Click to remove an element from a select html form using javascript
History and evolution of Javascript
List of Keywords and reverved words in Javascript
Using toString() in JavaScript to convert data types to String
Using parseInt() and parseFloat() in JavaScript to convert data types to Numbers
Typecasting in Javascript