gpt4 book ai didi

javascript - 如何禁用右键单击 IFRAME

转载 作者:搜寻专家 更新时间:2023-10-31 22:20:24 26 4
gpt4 key购买 nike

我在 MVC 网络应用程序的 IFrame 上显示了一个文档内容。不得复制和打印内容。我尝试使用两个函数 style="pointer-events:none;"禁用右键单击oncontextmenu="return false"对于 Iframe,它工作正常。但是在右键单击时,会显示“View Frame Source”、“View Source”的弹出窗口。我怎么能限制这个。!另外,如何限制打印屏幕选项。我知道还有其他实用程序,任何人都可以从中捕获数据。但是客户想要限制打印屏幕选项。

<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>

请任何帮助表示赞赏.. !!

最佳答案

为了禁用右键单击菜单,您可以使用以下代码段:

document.oncontextmenu = function() { 
return false;
};

我做了一个JSFiddle显示效果。

关于javascript - 如何禁用右键单击 IFRAME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26583033/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com