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

本文介绍如何使用CSS和HTML属性防止网页上的图片和内容被选中、复制及右键菜单操作,包括设置图片禁止选中、整体页面内容禁止选择、复制和右键功能的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在写页面的时候,需要在左上角加一个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 oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'>

关键就在  

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" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()"

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

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

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

<body onmousemove=/HideMenu()/ oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值