javascript 在 PHP 中右键单击禁用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13719096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 19:36:04  来源:igfitidea点击:

Right Click Disable in PHP

javascripthtmlbrowser

提问by rOcKiNg RhO

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?

我正在使用一个应用程序,其中使用了 ppt 幻灯片和视频。我想在所有浏览器中禁用右键单击,是否可以这样做?

回答by Kuf

No, PHP in server side, right click is client side.

不,PHP 在服务器端,右键单击是客户端。

you can achieve it by using jQuery:

你可以通过使用 jQuery 来实现它:

$(document).ready(function()
{ 
       $(document).bind("contextmenu",function(e){
              return false;
       }); 
})

回答by clement

Right click is a feature of your browser. YOu can't disable it through PHP (PHP generates HTML).

右键单击是浏览器的一项功能。你不能通过 PHP 禁用它(PHP 生成 HTML)。

In Javascript it's possible:

在 Javascript 中是可能的:

<body oncontextmenu="return false;">

回答by RaJeSh

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.

无论您做什么,都无法阻止用户完全访问您网站上的每一点数据。只需关闭浏览器上的 Javascript(或使用 NoScript 等插件),您编写的任何 Javascript 都可以变得没有实际意义。此外,无法禁用任何用户为您的网站简单地“查看源代码”或“查看页面信息”(或使用 wget)的能力。

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.

这不值得付出努力。它实际上不会起作用。它会使您的网站对用户产生积极的敌意。他们会注意到这一点并停止访问。这样做没有任何好处,只会浪费精力和丢失流量。

回答by iDhavalVaja

<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

//通过使用上面的代码,您的右键单击将被禁用,并且没有人可以复制您的页面内容

回答by Krishna Ghodke

Try this:
To disable right click in all the browser using javascript.

试试这个:
使用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>