徐伟轩博客-爱写歌的程序员思考和科普的日常自媒体

统计
TypechoJoeTheme
文章目录

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

徐伟轩博主
2020-10-21 09:06
/
0 评论
/
508 阅读
/
180 字
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()">

网页代码
赞(0)
赞赏
感谢您的支持,我们会继续努力哒!
版权:

徐伟轩博客-爱写歌的程序员思考和科普的日常自媒体

本文链接:

https://letus.top/archives/62.html(转载时需注明本文出处及文章链接)

如无特别注明,本站内容为原创。

如需转载或刊登,请联系我们获得授权。

评论 (0)
本篇文章评论功能已关闭

亲爱的朋友

一切伟大,源于勇敢的开始。

人生倒计时

今日已经过去小时
这周已经过去
本月已经过去
今年已经过去个月

标签云