首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >JavaScript 控制鼠标右键功能含:屏蔽右键菜单、屏蔽粘贴、屏蔽复制、屏蔽剪切、屏蔽选中

JavaScript 控制鼠标右键功能含:屏蔽右键菜单、屏蔽粘贴、屏蔽复制、屏蔽剪切、屏蔽选中

作者头像
程序猿的栖息地
发布2022-04-29 14:02:44
发布2022-04-29 14:02:44
4.1K0
举报

最近写了一个摄影素材的站点,网友只能浏览,为了自己版权利益,防止网友在网站中直接下载和引用未经本人同意的产品素材,特意写了几个JavaScript方法屏蔽电脑的右键功能。全网最简单的方法,屏蔽鼠标右键功能,防止复制和下载,记得收藏哦!

1、屏蔽右键菜单

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;

}

}

2、屏蔽粘贴

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;

}

}

3、屏蔽复制

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;

}

}

4、屏蔽剪切

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;

}

}

5、屏蔽选中

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;

}

}

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2017-12-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 程序猿的栖息地 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档