I am using an application in which ppt slides and and videos are used. I want to disable right click in all the browser, is it possible to do so?
-
Possible duplicate: http://stackoverflow.com/questions/737022/how-do-i-disable-right-click-on-my-web-page – GBD Dec 05 '12 at 08:36
-
It is possible yes with javascript but totally defeated with view source – Dale Dec 05 '12 at 08:36
-
Why would you want to do that. It's nothing but annoying for your users. It will not protect your files from being accessible. – Nathan Q Dec 05 '12 at 08:38
-
@NathanQ: some confidential matters are to be displayed that sy need to diable – rOcKiNg RhO Dec 05 '12 at 08:46
-
@GBD: may be. i didnt knw dat bfre – rOcKiNg RhO Dec 05 '12 at 08:47
5 Answers
No, PHP in server side, right click is client side.
you can achieve it by using jQuery:
$(document).ready(function()
{
$(document).bind("contextmenu",function(e){
return false;
});
})

- 17,318
- 6
- 67
- 91
Right click is a feature of your browser. YOu can't disable it through PHP (PHP generates HTML).
In Javascript it's possible:
<body oncontextmenu="return false;">

- 4,204
- 10
- 65
- 133
Dont do that
No matter what you do, you can't prevent users from having full access to every bit of data on your website. Any Javascript you code can be rendered moot by simply turning off Javascript on the browser (or using a plugin like NoScript). Additionally, there's no way to disable the ability of any user to simply "view source" or "view page info" (or use wget) for your site.
It's not worth the effort. It won't actually work. It will make your site actively hostile to users. They will notice this and stop visiting. There is no benefit to doing this, only wasted effort and lost traffic.

- 313
- 3
- 14
-
I totally disagree with you. I believe who ever wants to achieve this has a valid reason. Take for instant i want to set a form value to disabled=True. Any developer with basic knowledge on forms can enable the form and set preferred value or even inject sqli. Maybe he needs this and does not need to set it on all pages. – Ngatia Frankline Apr 12 '17 at 15:56
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$(this).bind("contextmenu", function(e) {
e.preventDefault();
});
});
</script>
<script type="text/JavaScript">
function killCopy(e){ return false }
function reEnable(){ return true }
document.onselectstart=new Function ("return false");
if (window.sidebar)
{
document.onmousedown=killCopy;
document.onclick=reEnable;
}
</script>
//By using above code you right click will be disabled as well as no one can copy your page content

- 7,619
- 5
- 28
- 44

- 153
- 1
- 10
Try this:
To disable right click in all the browser using javascript.
<script language="javascript">
var message="This function is not allowed here.";
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>

- 10,556
- 10
- 48
- 77

- 589
- 2
- 6
- 26