设为首页收藏本站

 找回密码
 立即注册

只需一步,快速开始

搜索
热搜: Discuz WordPress
查看: 4525|回复: 0

网页中禁止右键 查看 复制代码

[复制链接]
  • TA的每日心情
    可爱
    2025-4-18 12:34
  • 发表于 2021-11-5 21:34:47 | 显示全部楼层 |阅读模式 来自 福建
    1、禁止鼠标左右键
    1. <SCRIPT language=javascript>
    2. <!--
    3. if (window.Event)
    4. document.captureEvents(Event.MOUSEUP);
    5. function nocontextmenu(){
    6. event.cancelBubble = true
    7. event.returnValue = false;
    8. return false;
    9. }
    10. function norightclick(e){
    11. if (window.Event){
    12. if (e.which == 2 || e.which == 3)
    13. return false;
    14. }
    15. else
    16. if (event.button == 2 || event.button == 3){
    17. event.cancelBubble = true
    18. 18 event.returnValue = false;
    19. 19 return false;
    20. }
    21. }
    22. document.oncontextmenu = nocontextmenu; // for IE5+
    23. document.onmousedown = norightclick; // for all others
    24. //-->
    25. </SCRIPT>
    复制代码
    2、禁止鼠标左右键代码/禁止网页选中/禁止另存为/防复制代码
    1. <body oncontextmenu="return false" onselectstart="return false">
    2. <noscript><iframe src="/*.html>";</iframe></noscript>
    3. <script>
    4. function stop(){
    5. return false;
    6. }
    7. document.oncontextmenu=stop;
    8. </script>
    复制代码
    3、禁止选中代码
    1. <SCRIPT language=JavaScript>
    2. document.oncontextmenu=new Function("event.returnValue=false;");
    3. document.onselectstart=new Function("event.returnValue=false;");
    4. </SCRIPT>
    复制代码
    4、禁止另存为
    1. <noscript>
    2. <iframe src="/*.htm"></iframe>
    3. </noscript>
    复制代码
    5、防拷贝/复制代码
    1. <body leftmargin=0 topmargin=0 >
    复制代码
    6、禁止选择文本
    1. <script type="text/javascript">
    2. var omitformtags=["input", "textarea", "select"]
    3. omitformtagsomitformtags=omitformtags.join("|")
    4. function disableselect(e){
    5. if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
    6. return false
    7. }
    8. function reEnable(){
    9. return true
    10. }
    11. if (typeof document.onselectstart!="undefined")
    12. document.onselectstart=new Function ("return false")
    13. else{
    14. document.onmousedown=disableselect
    15. document.onmouseup=reEnable
    16. }
    17. </script>
    复制代码
    7、禁止网页另存为
    1. <noscript><iframe src="/*.html>";</iframe></noscript>
    复制代码
    8、禁止选择文本
    1. <script type="text/javascript">

    2. var omitformtags=["input", "textarea", "select"]

    3. omitformtagsomitformtags=omitformtags.join("|")

    4. function disableselect(e){
    5. if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
    6. return false
    7. }

    8. function reEnable(){
    9. return true
    10. }

    11. if (typeof document.onselectstart!="undefined")
    12. document.onselectstart=new Function ("return false")
    13. else{
    14. document.onmousedown=disableselect
    15. document.onmouseup=reEnable
    16. }
    17. </script>
    复制代码
    9、禁用右键
    1. <script>
    2. function stop(){
    3. return false;
    4. }
    5. document.oncontextmenu=stop;
    6. </script>
    复制代码
    或者在<body>里加上
    10、真正的鼠标右键屏蔽
    1. <script language="JavaScript">
    2. <!--

    3. if (window.Event)
    4. document.captureEvents(Event.MOUSEUP);

    5. function nocontextmenu()
    6. {
    7. event.cancelBubble = true
    8. event.returnValue = false;

    9. return false;
    10. }

    11. function norightclick(e)
    12. {
    13. if (window.Event)
    14. {
    15. if (e.which == 2 || e.which == 3)
    16. return false;
    17. }
    18. else
    19. if (event.button == 2 || event.button == 3)
    20. {
    21. event.cancelBubble = true
    22. event.returnValue = false;
    23. return false;
    24. }

    25. }

    26. document.oncontextmenu = nocontextmenu; // for IE5+
    27. document.onmousedown = norightclick; // for all others
    28. //-->
    29. </script>
    复制代码
    反之要取消也是找到以上相关代码取消就行了




    放置说明:以上代码按需要来使用,比如只想用一个禁止右键的,就选一个可以禁止右键的就可以,不用全部放到文件里。
    首先复制上面你需要用到的代码,放到你想要用到的页面(比如我只想门户首页里禁止右键,那就把这代码放到模板文件夹里的portal/index.php或index.htm里的最底部),一般是希望全站都有这功能,那就把代码放到公共的底部文件里:模板文件夹里的common/footer.php或footer.htm文件的最底部里。

    草根般深入探索与分享,就在我的菜园。
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册  

    本版积分规则

    亲爱的,赶快加入我们吧!
    X
    获取帮助
    X

    客服咨询

    菜心哥 旺旺客服

    微博收听

    鹭彩星微博

    工作时间

    8:30 - 23:00

    QQ|Archiver|手机版|小黑屋|老菜心 ( 闽ICP备16022933号-1 )|网站地图

    GMT+8, 2025-5-12 04:16 , Processed in 0.023626 second(s), 31 queries .

    Powered by Lucaixing! X3.5 Licensed

    © 2001-2025 Discuz! Team.

    快速回复 返回顶部 返回列表