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
  
      }
       }

Recommended Answers

All 4 Replies

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

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

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.