Gert Verhoeven

.NET Developer in C#, ASP.NET, DotNetNuke, ... at Ordina Belgium
posts - 5, comments - 5, trackbacks - 0

My Links

News

Archives

Post Categories

ASP.NET

General .NET

ASP.NET : Disable Left Click But Enable Right Click

Sometimes in your web application you will have a link to a file on the server.  Problems occur when the user clicks on the link and opens the file in the browser.  If the user wants to save the file he will get an error.  To force the user to dowload the file you can disable the left click but keep right clicking enabled.

To make the script accessible on all web pages I declared the script in the default.aspx file

<head id="Head" runat="server">
  <script language
="javascript">
    function
noLeftClick()
    {
      if (event.button==1)
      {
        alert('Please use the rightclick \"Save Target As\" Command to Download')
      }
    }
  </script
>
</
head>

In the html content you have to add the call to the javascript :

<a href=http://server.filename.xls onMouseOver='document.onmousedown=noLeftClick' onMouseOut='document.onmousedown=null'>filename</a>

 As you see, you can right click and save the target as, but you can not directly click on it.

Print | posted on Wednesday, May 16, 2007 2:11 AM | Filed Under [ ASP.NET ]

Feedback

Gravatar

# re: ASP.NET : Disable Left Click But Enable Right Click

Good idea, this post has been quoted here:

http://www.dotneturls.com/blogs/20070516/178/ASP_NET_Disable_Left_Click_But_Enable_Right_Click.aspx

thanks for sharing!
5/16/2007 3:11 AM | Webdiyer
Gravatar

# re: ASP.NET : Disable Left Click But Enable Right Click

i need a code that would allow the photo picked to enlarge, but not allow the picture to be printed.

Help
4/8/2008 1:17 AM | Annette
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: