HTML页面 用CSS实现禁止选中、复制和右键

摘要:最近在写页面的时候,需要在左上角加一个logo,但是复制的时候会把这张图片一块选中。那么我们可以通过CSS给它设置禁止选中,代码如下:

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

那么我们可以通过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页面内容禁止选择、复制、右键

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

<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()">

本文内容仅供个人学习、研究或参考使用,不构成任何形式的决策建议、专业指导或法律依据。未经授权,禁止任何单位或个人以商业售卖、虚假宣传、侵权传播等非学习研究目的使用本文内容。如需分享或转载,请保留原文来源信息,不得篡改、删减内容或侵犯相关权益。感谢您的理解与支持!

链接: https://shenqiku.cn/article/FLY_8291