实现网站内禁止右键和复制的代码

有时候客户或者网站开发人员出于版权保护,会需要实现在网站内禁止访客进行右击和复制的操作,这样的功能实现起来其实比较简单,今天徐伟轩博客就为大家简单介绍一下。

方法1

一段JS代码就能禁止网页鼠标右键和复制


1
2
3
4
5
6
7
8
9
10
11
12
13
<style type="text/css">
body {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>
<script langauge="javascript">
document.oncontextmenu=function(e){return false;}
</script>

当然,这个方法是测试了IE和谷歌浏览器,其他的没测试。
实现网站内禁止右键和复制的代码

方法2

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


1
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 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://letus.top/archives/238.html,转载请注明出处 来自[徐伟轩博客]。

0

评论0

没有账号?注册  忘记密码?