Welcome to Dream.In.Code
Getting Help is Easy!

Join 118,878 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,952 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Preventing Right Clicking

 
Reply to this topicStart new topic

Preventing Right Clicking, Easy to use code.

DeceitfulPillow
post 22 Jun, 2008 - 07:38 PM
Post #1


New D.I.C Head

*
Joined: 22 Jun, 2008
Posts: 26



Thanked 1 times
My Contributions


Put this between your <head> tags. When someone right-clicks, they should get a pop-up that reads, by default, "Please don't do that."

There is one problem though, IE's ActiveX and script blocker will prevent its use.


CODE
<script language="JavaScript">

<!--

var message="Please don't do that.";

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>


This post has been edited by DeceitfulPillow: 22 Jun, 2008 - 07:43 PM
User is offlineProfile CardPM

Go to the top of the page


MRJ
post 23 Jun, 2008 - 09:56 AM
Post #2


D.I.C Head

Group Icon
Joined: 13 Oct, 2007
Posts: 82


My Contributions


So will Firefox advanced JavaScript options. The only think preventing right click does is annoy users. Anyone who wants to can by-pass it with ease.
User is offlineProfile CardPM

Go to the top of the page

DeceitfulPillow
post 23 Jun, 2008 - 01:42 PM
Post #3


New D.I.C Head

*
Joined: 22 Jun, 2008
Posts: 26



Thanked 1 times
My Contributions


yh but lots of ppl have been asking for it that I can see.

I myself just you know. Tools >Page Info > Media

but, it may help someone.
User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 23 Jun, 2008 - 01:48 PM
Post #4


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 7,918



Thanked 83 times

Dream Kudos: 8100

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, GDI, Boo.Net

My Contributions


Also, all someone has to do is disable JavaScript and they get past it as well. Unfortunately there is no sure fire way to prevent a user from right-clicking
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/13/08 02:40AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month