100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 网站禁用鼠标右键php代码 JS实现禁止鼠标右键的功能

网站禁用鼠标右键php代码 JS实现禁止鼠标右键的功能

时间:2019-05-27 08:13:53

相关推荐

网站禁用鼠标右键php代码 JS实现禁止鼠标右键的功能

遇到网页上有精美图片或者精彩文字想保存时,通常大家都是选中目标后按鼠标右键,在弹出菜单中选择“图片另存为”或“复制”来达到我们的目的。但是,目前有许多网页都屏蔽了鼠标右键,那么用js如何实现禁止鼠标右键的功能呢?

1.与禁止鼠标右键相关的JS说明

document.οncοntextmenu=new Function("event.returnValue=false;");

document.onselectstart=new Function("event.returnValue=false;");

2.禁止鼠标右键火狐失灵

禁止鼠标右键 这个页面不能使用鼠标右键

if (window.Event){

document.captureEvents(Event.MOUSEUP);

}

function nocontextmenu(){

event.cancelBubble = true

event.returnValue = false;

return false;

}

function norightclick(e) {

if (window.Event) {

if (e.which == 2 || e.which == 3)

return false;

} else if (event.button == 2 || event.button == 3){

event.cancelBubble = true

event.returnValue = false;

return false;

}

}

document.oncontextmenu = nocontextmenu; // for IE5+

document.onmousedown = norightclick; // for all others

3.禁止选择文本

var omitformtags=["input", "textarea", "select"];

omitformtagsomitformtags=omitformtags.join("|");

function disableselect(e){

if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1){

return false;

}

}

function reEnable(){

return true;

}

if (typeof document.onselectstart!="undefined"){

document.onselectstart=new Function ("return false");

}else{

document.οnmοusedοwn=disableselect;

document.οnmοuseup=reEnable;

}

4.屏蔽ctrl按键

document.οnkeydοwn=function(){

if(event.ctrlKey)return false;

}

以上所述是小编给大家介绍的JS实现禁止鼠标右键的功能,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的,在此也非常感谢大家对脚本之家网站的支持!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。