如何禁用Inspect Element和f12 click?

时间:2017-07-28 12:22:32

标签: asp.net-mvc-4

我有一个通过iframe在新窗口中打开的PDF,但是当我禁用f12并检查Element时,它不能处理该PDF,它在PDF之外工作。

  <body>

     <div id="divPDFView" style="margin: auto;text-align: center;">

     </div>


    <div style="display:none;" id="divDocument">
    @if (Model.MyAccountList.Count > 0)
    {
        foreach (var items in Model.MyAccountList)
        {
            <a href="#" onclick="myPdf(this)" id="@items.PdfName">
             <div class="sm-video">
               ///There have some work
             </div>
         }
    }
 </body>

   <script>
    function myPdf(e) {
        var filen = e.id;
        debugger;
        window.open('@Url.Action("pdfshow", "MyAccount")?pdfname=' + filen);           
    }
</script>


      ///Here i show PDF From View Which is pdfshow
             <body>
              <div>
                @Html.Raw(TempData["Embed"])
              </div>
            </body>

这是我用来禁用F12和Inspect Element的JavaScript代码,但这是在PDF之外的工作。

        <script>
         $(document).ready(function () {
          debugger
           document.onmousedown = disableclick;
            status = "Right Click Disabled";
              function disableclick(event) {
               if (event.button == 2) {
                alert(status);
               return false;
           }
       }
    });
</script>

 <script type='text/javascript'>

    $(document).keydown(function (event) {
        debugger
        if (event.keyCode == 123) {
            return false;
        }
        else if (event.ctrlKey && event.shiftKey && event.keyCode == 73) {
            return false;  //Prevent from ctrl+shift+i
        }
    });
</script>

这是使用Iframe

创建PDF的控制器代码
 public ActionResult pdfshow(string pdfname = null)
    {
        string pdffile ="<iframe src='/Content/TutorialImage/TutorialPdf/" + 
                         pdfname + "#toolbar=0' width='800px' height='600px' 
                         id='myframe' oncontextmenu='return false;' >
                        </iframe>";

        TempData["Embed"] = pdffile;
        return View(TempData["Embed"]);
    }

0 个答案:

没有答案