首页 > 代码库 > javascript 屏蔽F5,BackSpace等各种按键
javascript 屏蔽F5,BackSpace等各种按键
Java代码
- function DisableF5(){
- with (event){
- // F5 and Ctrl+R
- if (keyCode==116 || (ctrlKey && keyCode==82)){
- event.keyCode = 0;
- event.cancelBubble = true;
- return false;
- }
- }
- }
- document.onkeydown = DisableF5;
Java代码
- function document.onkeydown()
- {
- if ((event.keyCode==8) || //屏蔽退格删除键
- (event.keyCode==116)|| //屏蔽 F5 刷新键
- (event.ctrlKey && event.keyCode==82)){ //Ctrl + R
- event.keyCode=0;
- event.returnValue=http://www.mamicode.com/false;
- }
- }
一,js屏蔽浏览器(IE和FireFox)的刷新功能
Java代码
- document.onkeydown=function()
- {
- if ((window.event.keyCode==116)|| //屏蔽 F5
- (window.event.keyCode==122)|| //屏蔽 F11
- (window.event.shiftKey && window.event.keyCode==121) //shift+F10
- )
- {
- window.event.keyCode=0;
- window.event.returnValue=http://www.mamicode.com/false;
- }
- if ((window.event.altKey)&&(window.event.keyCode==115))
- {
- //屏蔽Alt+F4
- window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");
- return false;
- }
- }
二,js屏蔽浏览器右键功能
Java代码
- 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。