移动端长按会复制等选项可以使用下述的代码屏蔽这个功能,将下述的css加到代码中即可
1 2 3 4 5 6 7 8 9 |
/*在手机浏览器中,长按可选中文本,但如果在应用中,会给人一种异样的感觉,最好还是禁用此功能为上*/ * { -webkit-touch-callout:none; -webkit-user-select:none; -khtml-user-select:none; -moz-user-select:none; -ms-user-select:none; user-select:none; } |
屏蔽浏览器右键菜单功能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
function forbidRight(){ 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 } event.button = 0 :左键 event.button = 1 :中间滚轮 event.button = 0 :右键 |
转载请注明:PHP笔记 » JavaScript屏蔽浏览器右键功能按钮