如何禁用右键单击Ifram Pdf文件 [英] How to disable Right Click on Ifram Pdf file

查看:862
本文介绍了如何禁用右键单击Ifram Pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请任何人都可以帮助我解决这个问题.我想在我的网页上使用Ifram显示pdf文件,但我想禁用对ifram的右键单击. 我的代码是贝娄

Please Any one can help me for solving this problem.I want to my web page show pdf file using Ifram, but i want just disable right click on ifram. My Code is Bellow

$(document).contextmenu(function () {
                                return false;
                            });

<iframe id="pdf"   src="<?= base_url('assets/uploads/' . $notice['file']); ?>#toolbar=0&scrollbar=0&navpanes=0&embedded=true&statusbar=0&view=Fit;readonly=true;disableprint=true;" 
                            style="width:100%; height:900px;" frameborder="0"></iframe>

推荐答案

您可以在javascript中尝试

You can try this in javascript

<script language="javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
Function disableclick(e)
{
  if(event.button==2)
   {
     alert(status);
     return false;  
   }
}
</script>

但是无论如何,只要关闭浏览器上的Javascript,就可以将您编写的任何Javascript设为静音.

But anyways any Javascript you code can be rendered mute by simply turning off Javascript on the browser.

此外,无法禁止任何用户简单地为您的网站查看源代码"或查看页面信息"并获得他们想要的内容.

Additionally, there's no way to disable the ability of any user to simply "view source" or "view page info" for your site and get what they want.

希望代码能为您提供帮助,然后您重新考虑禁用右键单击.

Hope the code helps you, and you reconsider disabling right click.

JS中的另一种方法:

One more way in JS :

document.addEventListener("contextmenu", function(e){
    e.preventDefault();
}, false);

此外,您的代码看起来像JQuery,所以这里是JQuery示例:

Also, your code looks like JQuery, so here's JQuery example :

$(function() {
    $(this).bind("contextmenu", function(e) {
        e.preventDefault();
    });
}); 

这篇关于如何禁用右键单击Ifram Pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆