h5设置网页不能选中,复制等操作,防被趴!

最近在写页面的时候,需要在左上角加一个logo,但是复制的时候会把这张图片一块选中。

HTML页面 用CSS实现禁止选中、复制和右键 HTML笔记 第1张

那么我们可以通过CSS给它设置禁止选中,代码如下:

.icon {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Chrome/Safari/Opera */
-khtml-user-select: none; /* Konqueror */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently not supported by any browser */
}

添加禁止代码后,该图片就不能被选中了。

HTML页面 用CSS实现禁止选中、复制和右键 HTML笔记 第2张

HTML页面内容禁止选择、复制、右键

刚才在一个站点的源代码的的时候发现的,其实原来真的很简单

<body leftmargin=0 topmargin=0 οncοntextmenu='return false' οndragstart='return false' onselectstart ='return false' οnselect='document.selection.empty()' οncοpy='document.selection.empty()' onbeforecopy='return false' οnmοuseup='document.selection.empty()'>

关键就在  

οncοntextmenu='return false'
οndragstart='return false' 
onselectstart ='return false' 
οnselect='document.selection.empty()' 
οncοpy='document.selection.empty()' 
onbeforecopy='return false' 
οnmοuseup='document.selection.empty()'

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

topmargin="0" οncοntextmenu="return false" οndragstart="return false" onselectstart ="return false" οnselect="document.selection.empty()" οncοpy="document.selection.empty()" onbeforecopy="return false" οnmοuseup="document.selection.empty()"

1、禁止网页另存为:在<body>后面加入以下代码: 

<noscript> 
<iframe src="*.htm"></iframe> 
</noscript>

2、禁止网页内容复制.粘贴:在<body>中加入以下代码: 

<body οnmοusemοve=/HideMenu()/ οncοntextmenu="return false" οndragstart="return false" onselectstart ="return false" οnselect="document.selection.empty()" οncοpy="document.selection.empty()" onbeforecopy="return false" οnmοuseup="document.selection.empty()">
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值