aspx Tutorial

.NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services, .NET articles, Sharepoint 2010, visual studio 2010,Aamir Hasan,IT, Building Your First Web Application Project
Advertise Here

Toolbar

Get our toolbar!

Advertize



Posted by Aamir Hasan   on Thursday, October 7, 2010 Total Views:  

You can easily find some javascript code over the internet to disable right click on your page. but jQuery make it so simple by using oneline of code.jQuery library provids a bind
method

bind()

Attaching behavior to a document is called bind(). I have bind contextmenu event to document.

Syntax

.bind( eventType, [ eventData ], handler(eventObject) )

Why we disable right click

  • Most of people wants to disable right click in their site because of "Save as images" but there are other options to save image. Before going to display HTML and images, it is download on own machine, its mean you can easily take images from your machine.
  • To protect links to open in new tab. But, there are other options.

Add following code under the HEAD tag of your aspx page

<head>

<
script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

    <script type="text/javascript" language="javascript">

        $(document).ready(function () {

            $(document).bind("contextmenu", function (e) {

                return false;

            });

        });

    </script>

</head>


Click here to see demo and source code

Category: All | asp.net | jQuery
Protected by Copyscape Online Plagiarism Tool

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5