zoukankan      html  css  js  c++  java
  • 禁止复制文字,下载图片的方法

    本文转载来:canlynet的博客 记载自此希望自己能记住

    1.body用如下方式:

    <body oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'> 2.禁止用Ctrl+c复制,我们禁止Ctrl键:

    <script type="text/javascript"> function DisableCopyKey()   {   if(event.keyCode==17)     document.selection.clear();   }   document.onkeydown=DisableCopyKey; </script>

    3.由于firfox浏览器对body中onselectstart等动作不支持,所以需要用css的方法禁止。

    <style type="text/css">

    body {-moz-user-select: -moz-none;}

    </style>

    4.防止下载下来改源码再复制,在<body ........................>下一行添加:

    <noscript><iframe src=*.html></iframe></noscript>

    经过如上步骤,用户在ie和firefox中都无法选择文字,也就无法复制了。同时,也无法下载这个页面,这样一来,想要复制文字和图片,都不容易,除非浏览器有下载图片的功能,但文字肯定是无法复制了。

  • 相关阅读:
    Leetcode Unique Binary Search Trees
    Leetcode Decode Ways
    Leetcode Range Sum Query 2D
    Leetcode Range Sum Query
    Leetcode Swap Nodes in Pairs
    Leetcode Rotate Image
    Leetcode Game of Life
    Leetcode Set Matrix Zeroes
    Leetcode Linked List Cycle II
    CF1321A
  • 原文地址:https://www.cnblogs.com/jianheng/p/4102598.html
Copyright © 2011-2022 走看看