472,119 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

How disable the F5 key in Mozilla

Hi,
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?

<script>
document.onkeydown = function(){

if(window.event && window.event.keyCode == 116){
window.event.keyCode = 505;
}
if(window.event && window.event.keyCode == 505){
return false;
}

}

</script>

May 24 '06 #1
7 17825
You can find very simple solutions here:
http://www.gklein.org/tests/js/disablekey.html

May 24 '06 #2
On 24/05/2006 12:18, prado wrote:
I am trying to disable the F5 key in Mozilla.


Well, stop that then and fix the real problem, instead.

If refreshing breaks something, then attempting to prevent that action
doesn't fix anything. More importantly, you'll never really succeed:
there are other means besides F5, including other keystrokes, and it
will clearly do nothing for users with scripting disabled.

Finally, have you thought the consequences through properly? If a
document doesn't load completely due to network problems, but sufficient
data comes through to disable refreshing, what do you think the user
will do if they can't reload?

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
May 24 '06 #3
I can not disable F5 key in Mozilla. I have tried it but it don't work.
Can you help me, please?

Jun 2 '06 #4
prado said the following on 6/2/2006 8:27 AM:
I can not disable F5 key in Mozilla.
Good.
I have tried it but it don't work.
And that is how it should be.
Can you help me, please?


Redesign your app so that F5 doesn't fubar it.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 2 '06 #5
VK

prado wrote:
I can not disable F5 key in Mozilla. I have tried it but it don't work.
Can you help me, please?


The linked solution does work - unfortunately - even for the latest FF
1.5.0.4
Today later I'll file a bug to bugzilla so they fix it (unless there
are volunteers to do it immediately ?)

Jun 2 '06 #6
VK said the following on 6/2/2006 3:46 PM:
prado wrote:
I can not disable F5 key in Mozilla. I have tried it but it don't work.
Can you help me, please?
The linked solution does work - unfortunately - even for the latest FF
1.5.0.4


No, it does not "work" at all.
Today later I'll file a bug to bugzilla so they fix it (unless there
are volunteers to do it immediately ?)


To fix what? The ineptness of webpage authors that can't write a decent
app that won't die if the F5 key is pressed? Good luck with that but I
don't think filing with bugzilla can fix that problem.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 2 '06 #7
teppei
1
Randy Webb & Michael Winter,
I think you are too close minded...

To disable the F5 key doesn't necessarily mean that
the programmer can't solve a "refresh issue".

e.g.
I'm moving a "mainframe application" to a web application.
I don't want the users to change their way of working...
They are used to:
- press F1 to inqury
- press F2 to insert
- press F3 to update
- press F4 to delete
- press F5 to release
....

As you can see I need to intercept the function keys and to
change their functionality.

--------------------------------------------

Back to the topic...

This is what I've done:

/*
* Intercept all the 'function keys' and invokes the related submit input
* (if one exists). This method must be invoked when a "keydown" event occurs
*/
function interceptKeyDown(e) {

keyCode = e.keyCode;

if( keyCode >= asciiF1 && keyCode <= asciiF12 ||
keyCode >= asciiPgUp && keyCode <= asciiHome ) {

e.keyCode = 505;
clickButton( keyCode );
return false;
}
}
attachEventListener(document,"keydown",interceptKe yDown,true);

/*
* Intercept all the 'function keys' and invokes the related submit input
* (if one exists). This method must be invoked when a "keypress" event occurs
*/
function interceptKeyPress(e) {[indent]
if( !e ) {

if( window.event ) e = window.event;
else return;
}

//NS 4, NS 6+, Mozilla 0.9+, Opera
if( typeof( e.which ) == 'number' ) {

var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : void 0;

if(e.charCode == null || e.charCode == 0 ){

if( keyCode >= asciiF1 && keyCode <= asciiF12 ||
keyCode >= asciiPgUp && keyCode <= asciiHome ) {

e.stopPropagation();
e.preventDefault();
clickButton( keyCode );
}
}
}
}
attachEventListener(document,"keypress",interceptK eyPress,true);


/*
* According to the type of browser, adds a new event listener to
* the specified object ,for the requested event, binded to the
* specific function.
*/
function attachEventListener( obj, type, func, capture ) {

if(window.addEventListener){ // Mozilla, Netscape, Firefox

obj.addEventListener( type, func, capture );
} else { // IE

obj.attachEvent( 'on' + type, func );
}
}


the function clickButton( keyCode ) changes according to your specifications
Jun 9 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Kate Riley | last post: by
1 post views Thread by Prashant Joshi | last post: by
3 posts views Thread by David Rwj Cherry CS2000 | last post: by
11 posts views Thread by MasonC | last post: by
6 posts views Thread by Al Cohen | last post: by
8 posts views Thread by alamodgal | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.