Home > Code > Javascript > How to disable Right Click on the page using JavaScript?

How to disable Right Click on the page using JavaScript?

by Thamil   on Jun 13, 2011   Category: Javascript   |  Views: 2112    |  Points: 25   |  Gold 

Below is the sample JavaScript code snippet to disable right clicks on the page and prevent to viewing the source code or saving images from the page.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Disable Right Click using Javascript</title>

<script language="JavaScript" type="text/javascript">
var message = "";
function CheckRightclick(keyp) {
if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2)
alert('Right click disabled'); return false;
document.onmousedown = CheckRightclick;
<form id="form1" runat="server">
<div> Test - Disable Right Click using Javascript

Post Code  |  Code Snippet Home

Recent Posts

User Responses

No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts