Disable right click on a web page using javascript

I am workin on Content Management Project.I am developing portlets using IBM RAD tool.I need to show images and links which i want to be right click disabled using javascript.
Ramkrishna_KumarAsked:
Who is Participating?
 
yo_s_cantaConnect With a Mentor Commented:
If you want hole document disabled try this

var message="Function Disabled!";
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")

Open in new window

0
 
Michel PlungjanIT ExpertCommented:
Quickest:

onContentMenu="return false"

Firefox 6?
0
 
Michel PlungjanIT ExpertCommented:
Isn't this more clever?


var message="Function Disabled!";
function myclick(e){
  if ((e && (e.which==2||e.which==3)  || 
      (window.event && window.event.button==2)) {
    alert(message);
    return false;
  }
}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=myclick;
}
document.oncontextmenu=function() {alert(message);return false}

Open in new window

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
yo_s_cantaCommented:
yo_s_canta example work's for all browsers
0
 
Ramkrishna_KumarAuthor Commented:
Thanks buddy its helped a lot,i could do that.
0
 
Michel PlungjanIT ExpertCommented:
I think a split was in order here...
0
All Courses

From novice to tech pro — start learning today.