如何禁用右键点击IFRAME [英] How to disable right click on IFRAME
问题描述
我在MVC Web应用程序中的IFrame上显示文档内容。内容不应该被复制和打印。我试图禁用右键使用两个函数style =pointer-events:none; oncontextmenu =返回falseiframe,它工作正常。
但是在右键单击时,会弹出查看源代码,查看源代码弹出窗口。我怎样才能限制这一点。
另外,如何限制打印屏幕选项。我知道还有其他的工具可以从任何人可以捕获数据的地方找到。但是客户想要限制打印屏幕选项。
< script lang = JavaScript>
函数clickIE(){
if(document.all){
return false;
函数clickNS(e){
if(document.layers ||(document.getElementById&&!document.all)){
if(e.which == 2 || e.which == 3){
return false;
}
}
}
if(document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = clickNS;`在此处输入代码`
}
else {
document.onmouseup = clickNS;
document.oncontextmenu = clickIE;
document.oncontextmenu = new Function(return false)
$ b
< body oncontextmenu =return falseonkeydown = if((arguments [0] || window.event).ctrlKey)return false>
< div id =div1style =background-color:Red; height:120px>
< / div>
请任何帮助表示赞赏..
为了禁用右键单击菜单,您可以使用以下代码片段:
document.oncontextmenu = function(){
return false;
};
我做了一个 JSFiddle ,显示效果。
I have a document content displayed on IFrame in MVC web application. The content should not be copied and printed . I tried to disable right click using two functions style="pointer-events:none;" oncontextmenu="return false" for Iframe, which is working fine. But on right click, the pop up with 'View Frame Source', 'View Source' are displaying. How can I restrict this.! Also, how to restrict the print screen option. I know there are other utilities from where anybody can capture data. But the client wants to restrict the print screen option.
<script lang=JavaScript>
function clickIE() {
if (document.all) {
return false;
}
}
function clickNS(e) {
if (document.layers || (document.getElementById && !document.all)) {
if (e.which == 2 || e.which == 3) {
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = clickNS;`enter code here`
}
else {
document.onmouseup = clickNS;
document.oncontextmenu = clickIE;
}
document.oncontextmenu = new Function("return false")
<body oncontextmenu="return false" onkeydown="if ((arguments[0] || window.event).ctrlKey) return false" >
<div id="div1" style="background-color:Red; height:120px">
<iframe id="id1" src="" name="I1" scrolling="no" height="100%" width="100%" marginwidth ="0" marginheight="0" onload="disableContextMenu();" style="pointer-events:none;" />
</div>
Please Any help appreciated.. !!
In order to disable the right click menu you could use the following snippet:
document.oncontextmenu = function() {
return false;
};
I made a JSFiddle that displays the effect.
这篇关于如何禁用右键点击IFRAME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!