0

I am trying to disable the F5 key in Mozilla. I have the next code in
javascript that it is working in Internet Explorer but it is not
working in Mozilla. how can I disable the F5 key in Mozilla?

Code:

function checkKeyCode(evt)
        {
         var evt = (evt) ? evt : ((event) ? event : null);

      var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
   
      if(event.keyCode==116)
   
      {

      evt.keyCode=0;
  
      return false
  
      }
       }

Edited by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

3
Contributors
4
Replies
7
Views
7 Years
Discussion Span
Last Post by Troy III
0

Using mootools I'd use this code:

window.addEvent('keydown', function(event) {
   var e = new Event(event);
    if(e.code == 116)
    {
        e.stop();
    }
});

This code has been tested to work under FF3.5

Event-handling on the web is always good to let a framework take care of because it's so different from browser to browser (at least it's completely different in IE than in any other browser).

HTH

0

thank u for reply
i was tryed ur code not working mozilla browser..

Did you include the mootools-framework as I stated? I tested this code myself using Mozilla Firefox 3.5 (FF3.5), and it worked without a problem. But of cause, if the framework is missing, nothing will work.

0

Here, - catch this:

function disableRefresh(netscape){
	var F5=(netscape||event).keyCode;
		if(F5==116){
			if(!netscape){event.keyCode=0}
			return false;
			}
	}
document.onkeydown=document.onkeypress=disableRefresh;
//IE, FX, OP, ++ Troy III

p.s.: adding 100KB of JS code for a simple task is pretty much expensive; Especially when you are forced to include all of that junk just to be able to expand your script functionality to another less than 35% of existing browsers.
I personally hate pages forcing me to download 100KB++ so I could see some silly rollover effect.

Edited by Troy III: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.