zoukankan      html  css  js  c++  java
  • 网页禁止复制

    今天遇到了客户要求网页不可复制的要求,在百度中寻找,得到如下答案,非常好,随记下来

      非常感谢网络中各位大神的分享,也愿能够传播这种精神



    用JS禁止复制网页内容<Script Language=javascript>
    function key(){
    //if(event.shiftKey){
    //window.close();}
    //禁止shift
    if(event.altKey){
    alert('禁止CTRL-C复制本贴内容');}
    //禁止alt
    if(event.ctrlKey){
    alert('禁止CTRL-C复制本贴内容');}
    //禁止ctrl
    return false;}
    document.onkeydown=key;
    if (window.Event)
    document.captureEvents(Event.MOUSEUP);
    //swordmaple javascript article.
    //from www.XXXX.com
    //function nocontextmenu(){
    //event.cancelBubble = true
    //event.returnValue = false;
    //return false;}
    function norightclick(e){
    if (window.Event){
    if (e.which == 2 || e.which == 3)
    return false;}
    else
    if (event.button == 2 || event.button == 3){
    event.cancelBubble = true
    event.returnValue = false;
    return false;}
    }
    function Click(){
    alert('禁止右键粘贴本贴内容');
    window.event.returnValue=false;
    }
    document.oncontextmenu=Click;
    </Script>

    一个更简单的方法就是在<body>中加入如下的代码,这样鼠标的左右键都失效了.

    topmargin="0" oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()"

    1.禁止网页另存为:在<body>后面加入以下代码:
    <noscript>
    <iframe src="*.htm"></iframe>
    </noscript>

    2.禁止网页内容复制.粘贴:在<body>中加入以下代码:
    <body onmousemove=HideMenu() oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">
  • 相关阅读:
    解决 git 同步时 Everything up-to-date
    vs2019 git Authentication failed for xxx
    vs2015发布项目到虚拟主机组策略阻止csc.exe程序问题
    vs2017 使用 reportviewer
    var,dynamic的用法
    水晶报表报无法在资源中找到报表,请重新创建项目 错误
    css隐藏元素的方法
    css-浮动与清除浮动的原理详解(清除浮动的原理你知道吗)
    正则并不适合严格查找子串
    浏览器加载、渲染过程总结
  • 原文地址:https://www.cnblogs.com/ruiying/p/3968888.html
Copyright © 2011-2022 走看看