javascript - 禁用 Ctrl+A、Ctrl+C 键功能到 HTMl 页面

标签 javascript html keyboard

<分区>

如何禁用整个页面的 Ctrl+Actrl+C 键?我想禁用键盘的复制、粘贴功能。我发现了一些仅禁用一个文本框的链接。但我想禁用整个 HTML 页面的 ctrl 功能。

我将下面的代码粘贴到标签中,并在主体 onload 函数中添加了 disablePage

<!DOCTYPE html>
<html lang="en">
<head>
    <title>html2canvas example</title>
 <script type="text/javascript" src="img/html2canvas.js"></script>
<script language=JavaScript>
function ieClicked() {
    if (document.all) {
        return false;
    }
}
function firefoxClicked(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=firefoxClicked;
}else{
    document.onmouseup=firefoxClicked;
    document.oncontextmenu=ieClicked;
}
document.oncontextmenu=new Function("return false")
function disableselect(e){
    return false
    }
    function reEnable(){
    return true
    }
    document.onselectstart=new Function ("return false")
    if (window.sidebar){
    document.onmousedown=disableselect
    document.onclick=reEnable
    }
</script>
    <style>
    canvas{border:1px solid #222}
    </style>     
</head>
<body>
   <a class="upload"  >Upload to Imgur</a>  
   <a href="#" download="canvasexport.pdf" onclick="window.print()" ><img src="images/print-icon.png" alt="Print" width="16" height="16" ></a>

   <a href="#" id="download" download="diversio.pdf" onclick="printImg();"> 
   <img src="images/print-icon.png" alt="Print" width="16" height="16" >
   </a> 

    <h2>this is <b>bold</b> <span style="color:red">red</span></h2>   
    <p> Feedback form with screenshot This script allows you to create feedback forms which include a screenshot, 
    created on the clients browser, along with the form. 
    The screenshot is based on the DOM and as such may not be 100% accurate to the real 
    representation as it does not make an actual screenshot, but builds the screenshot based on the 
    information available on the page. How does it work? The script is based on the html2canvas library,
     which renders the current page as a canvas image, by reading the DOM and the different styles applied 
     to the elements. This script adds the options for the user to draw elements on top of that image, 
     such as mark points of interest on the image along with the feedback they send.
      It does not require any rendering from the server, as the whole image is created on the clients browser.
       No plugins, no flash, no interaction needed from the server, just pure JavaScript! Browser compatibility Firefox 3.5+ Newer versions of Google Chrome, Safari & Opera IE9
    </p>



</body>
</html>

最佳答案

试试这个:

function disableselect(e) {
    return false;
}

function reEnable() {
    return true;
}

document.onselectstart = new Function("return false");

if (window.sidebar) {
    document.onmousedown = disableselect;
    document.onclick = reEnable;
}

将此放在您的 <head> 中标签,用户无法选择您页面上的文本。但是,无法保证可以防止您的内容被盗。有经验的互联网用户可以轻松绕过上述 JavaScript。例如。如果浏览器的 JavaScript 被禁用,代码将无法运行。工作副本在 here 中可用.

关于javascript - 禁用 Ctrl+A、Ctrl+C 键功能到 HTMl 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19829078/

相关文章:

javascript - 未为寻宝脚本保存 Cookie

javascript - 有没有一种简单的方法来确定 HTML 元素的内容类别?

javascript - 替换 href http ://with//的脚本

javascript - 我怎样才能随机播放两个js数组而不使它们不匹配

css - 如何让div充满浏览器窗口

php - 如何为谷歌字体指定缓存验证器

flutter - 如何从父小部件检测子部件的焦点

ios - 键盘没有提供多个 UIWindows

安卓软键盘不工作

Javascript 更改输入值而不覆盖值