实现网站内禁止右键和复制的代码
10月21
有时候客户或者网站开发人员出于版权保护,会需要实现在网站内禁止访客进行右击和复制的操作,这样的功能实现起来其实比较简单,今天徐伟轩博客就为大家简单介绍一下。
方法1
一段JS代码就能禁止网页鼠标右键和复制
<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
更简单的方法就是在
中加入如下的代码,这样鼠标的左右键都失效了.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()"
禁止网页内容复制和粘贴:在
中加入以下代码:<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/62.html(转载时需注明本文出处及文章链接)
如无特别注明,本站内容为原创。
如需转载或刊登,请联系我们获得授权。