可以禁止用户右键,使用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 })在网页开发中,有些时候我们不想让用户去复制或者粘贴该网页的东西,那么下面的几个方法就非常有用了!
//屏蔽右键菜单document.oncontextmenu = function (event){
if(window.event){
event = window.event
}try{
var the = event.srcElement
if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
return false
}
return true
}catch (e){
return false
}
} //屏蔽粘贴
document.onpaste = function (event){
if(window.event){
event = window.event
}try{
var the = event.srcElement
if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
return false
}
return true
}catch (e){
return false
}
} //屏蔽复制
document.oncopy = function (event){
if(window.event){
event = window.event
}try{
var the = event.srcElement
if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
return false
}
return true
}catch (e){
return false
}
} //屏蔽剪切
document.oncut = function (event){
if(window.event){
event = window.event
}try{
var the = event.srcElement
if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
return false
}
return true
}catch (e){
return false
}
} //屏蔽选中
document.onselectstart = function (event){
if(window.event){
event = window.event
}try{
var the = event.srcElement
if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
return false
}
return true
} catch (e) {
return false
}
}
网页退出提示的方法:
window.onbeforeunload = function(event){event = event || window.event
event.returnValue = ' '
}
移动端中,屏蔽类似iphone的默认滑动事件用一下方法:
//禁用浏览器的默认滑动事件var preventBehavior = function(e) {
e.preventDefault()
}
// Enable fixed positioning
document.addEventListener("touchmove", preventBehavior, false)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)