在html中怎么设置内容不能复制

在html中怎么设置内容不能复制,第1张

一个更简单的方法就是在<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()">

可以禁止用户右键,使用js *** 作禁止,参考以下代码

<script type="text/javascript">

document.oncontextmenu=function(e){return false}

</script>  

<body onselectstart="return false">

也可以直接禁止用户选中页面从而实现禁止复制的目的,可以在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  

}

以上两种方法都可实现禁止用户复制。

禁止复制

οncοntextmenu='return false'    //禁止右键

οndragstart='return false'    //禁止拖动

onselectstart ='return false'    //禁止选中

οnselect='document.selection.empty()'    //禁止选中

οncοpy='document.selection.empty()'    //禁止复制

onbeforecopy='return false'   // 禁止复制

οnmοuseup='document.selection.empty()'

*{

  moz-user-select: -moz-none

  -moz-user-select: none

  -o-user-select:none

  -khtml-user-select:none

  -webkit-user-select:none

  -ms-user-select:none

  user-select:none

}

长按事件document.addEventListener("touchstart", function (e) {     console.log('touchstart')     timer = setTimeout(function () {         console.log('LongPress')         e.preventDefault()         LongPress(parentObj)     }, 800) }) document.addEventListener("touchmove", function (e) {     console.log('touchmove')     clearTimeout(timer)     timer = 0 }) document.addEventListener("touchend", function (e) {     console.log('touchend')     clearTimeout(timer)     if (timer != 0) {         alert('这是点击,不是长按')     }     return false })


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/7004392.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-31
下一篇 2023-03-31

发表评论

登录后才能评论

评论列表(0条)

保存