• 屏蔽右键代码(防止网页恶意复制)


    关于如何屏蔽右键复制的代码。大概有如下几种:
    <head>语句下输入

    1. <body onselectstart="return false;" oncontextmenu="return false;" >

    系统首页文件(default.asp)和日志文件(article.asp)最底下加入如下代码即可.这两个文件都在根目录下.

    1. <noscript>
    2. <iframe scr="*.htm"></iframe>
    3. </noscript>
    4. <script language="JavaScript">
    5. document.oncontextmenu=new Function("event.returnValue=false;");
    6. document.onselectstart=new Function("event.returnValue=false;");
    7. </script>

    优点是简单易行,但保护不够,很容易破解。
    找到的一些办法:
    第一种 禁止右键、Ctrl键和复制功能的JS代码

    有的t网站页面禁止使用右键和复制功能,甚至连Ctrl键也禁止掉了,这个效果是如何实现的呢?其实很简单就是调用了一段JS代码而已。
    下面文本框中就是实现效果所需代码:

    1. function click(e) {
    2. if (document.all) {
    3. if (event.button==1||event.button==2||event.button==3) {
    4. oncontextmenu='return false';
    5. }
    6. }
    7. if (document.layers) {
    8. if (e.which == 3) {
    9. oncontextmenu='return false';
    10. }
    11. }
    12. }
    13. if (document.layers) {
    14. document.captureEvents(Event.MOUSEDOWN);
    15. }
    16. document.onmousedown=click;
    17. document.oncontextmenu = new Function("return false;")
    18. var travel=true
    19. var hotkey=17 /* hotkey即为热键的键值,是ASII码,这里99代表c键 */
    20. if (document.layers)
    21. document.captureEvents(Event.KEYDOWN)
    22. function gogo(e)
    23. { if (document.layers) {
    24. if (e.which==hotkey&&travel){
    25. alert("操作错误.或许是您按错了按键!"); } }
    26. else if (document.all){
    27. if (event.keyCode==hotkey&&travel){ alert("操作错误.或许是您按错了按键!"); }}
    28. }
    29. document.onkeydown=gogo

    把上面的代码另存为一个JS文件,然后在想实现此效果的页面用<!--#include file="*.js" -->调用即可,*代表你另存的文件名!
    第二种 禁用右键并自动导航
    脚本说明:
    把如下代码加入<body>区域中

    1. <script language="javascript">
    2. if (navigator.appName.indexOf("Internet Explorer") != -1)
    3. document.onmousedown = noSourceExplorer;
    4. function noSourceExplorer()
    5. {
    6. if (event.button == 2 | event.button == 3)
    7. {
    8. alert("禁止右键...去首页!");
    9. location.replace("http://xiaoc.icpcn.com");
    10. }
    11. }
    12. </script>

    第三种 禁用右键代码
    将以下代码加到〈head〉与〈/head〉之间

    1. <script language="JavaScript">
    2. document.oncontextmenu=new Function("event.returnValue=false;");
    3. document.onselectstart=new Function("event.returnValue=false;");
    4. </script>

    优点是使用了JS脚本,但是比较复杂,也很容易破解。

    推荐使用的方法:
    网页脚本中(header.asp)插入以下代码:

    1. <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()'>

    上面代码的意思是当鼠标选中文字时为空
    优点是代码容易实现,不需要JS脚本的支持。且在一般的破解复制后,也会清空剪贴板。
    其中,我去除了onmouseup='document.selection.empty()',因为这段代码的意思是当鼠标键弹起时,选择的内容为空,这样就会影响正常的登陆哦。

  • 相关阅读:
    java 反射 invoke()的异常问题记录
    windows安装nginx可视化工具nginxWebUI
    Springboot+Mybatis+Clickhouse+jsp 搭建单体应用项目(三)(添加增删改查)
    Springboot+Mybatis+Clickhouse+jsp 搭建单体应用项目(二)(添加日志打印和源码地址)
    Springboot+Mybatis+Clickhouse+jsp 搭建单体应用项目(一)
    mac + docker+单击clickhouse+Dbeaver安装全套
    线程中使用for循环的add或remove方法的两种方案
    map数据按照list排序
    oracle dbca 【bug】:JAVA_JIT_ENABLED=false
    Ubuntu(Debian):apt-get:处理repository数字签名无效、过期、没有签名:即 如何强制 apt-get update?
  • 原文地址:https://www.cnblogs.com/hfzsjz/p/2591206.html
Copyright © 2020-2023  润新知