Recent Posts

Sunday, July 13, 2008

Block user from right clicking your web site

Just copy and paste the java script code given below to block the users from right
clicking on your web site.

function right(e) {
if (navigator.appName == 'Netscape' &&
(e.which == 3 e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' &&
(event.button == 2 event.button == 3)) {
alert("Please don't right click , Thanks Prateek!!");
return false;
}
return true;
}

document.onmousedown=right;
document.onmouseup=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=right;
window.onmouseup=right;
// End -->

Related Posts by Categories




2 comments:

Colin Angus Mackay said...

You don't seem to have escaped your javascript code, however if I right click, I get a nice little dialog. However, I can still get at the functionality of the right click by pressing the context menu key on my keyboard.

rprateek said...

I was just playing around this code, I haven't actually looked into not allowing the user from pressing the context menu. If i get time I will definately post it.

Thanks Angus

Post a Comment