春哥技术源码论坛

 找回密码
 立即注册
 

响应式网站源码任意下载

2020最新暴利项目海量素材源码任意下载
阿里云优惠码

低价定制APP

低价H5响应式网站建设
阿里云备案码广告位招租50元/每月轻松暴利赚钱
查看: 1652|回复: 0

html网站禁止复制选择复制粘贴方法总结

[复制链接]
  • TA的每日心情
    开心
    2024-4-18 22:43
  • 签到天数: 81 天

    [LV.6]常住居民II

    1416

    主题

    1189

    回帖

    3万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    39080
    发表于 2017-3-16 08:38:55 | 显示全部楼层 |阅读模式
    HTML,JS禁止鼠标右键、禁止全选、复制、粘贴的方法!
    禁止鼠标右键、禁止全选、复制、粘贴;
    oncontextmenu事件禁用右键菜单;
    js代码:
    document.oncontextmenu = function(){    event.returnValue = false;}// 或者直接返回整个事件document.oncontextmenu = function(){    return false;}onselectstart事件禁用网页上选取的内容;
    js代码:
    document.onselectstart = function(){    event.returnValue = false;}// 或者直接返回整个事件document.onselectstart = function(){    return false;}oncopy事件禁用复制;
    js代码:
    document.oncopy = function(){    event.returnValue = false;}// 或者直接返回整个事件document.oncopy = function(){    return false;}以上三种事件,如果只想单纯的禁用鼠标右键,和复制粘贴,还可以将它们直接写到HTML中的body上面;
    <body oncontextmenu = "return false" ></body><body onselectstart = "return false" ></body><body oncopy = "return false" ></body>
    禁用鼠标事件
    document.onmousedown = function(e){    if ( e.which == 2 ){// 鼠标滚轮的按下,滚动不触发        return false;    }    if( e.which==3 ){// 鼠标右键        return false;    }}禁用键盘中的ctrl、alt、shift
    document.onkeydown = function(){    if( event.ctrlKey ){        return false;    }    if ( event.altKey ){        return false;    }    if ( event.shiftKey ){        return false;    }}

    关键就在    oncontextmenu='return false'
      ondragstart='return false'
      onselectstart ='return false'
      onselect='document.selection.empty()'
      oncopy='document.selection.empty()'
      onbeforecopy='return false'
      onmouseup='document.selection.empty()'
    一个更简单的方法就是在<body>中加入如下的代码,这样鼠标的左右键都失效了.

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

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


    2.禁止网页内容复制.粘贴:在<body>中加入以下代码:
    <body onmousemove=/HideMenu()/ ondragstart="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onmouseup="document.selection.empty()">

    春哥技术博客,精品商业VIP源码,我们致力于为中小站长建站降低成本,所有源码放心购买,没有春哥币?点击这里,或者手动付款后给客服QQ留言:2931393342,手动付款,点击这里
    回复

    使用道具 举报

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

    本版积分规则

    QQ|Archiver|手机版|小黑屋|春哥技术源码论坛 |Sitemap

    GMT+8, 2024-4-29 13:23 , Processed in 0.064124 second(s), 33 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

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