We're calling on all EU-based Mozillians with iOS or iPadOS devices to help us monitor Apple’s new browser choice screens. Join the effort to hold Big Tech to account!

Este site irá ter funcionalidade limitada enquanto fazemos manutenção para melhorar a sua experiência. Se um artigo não resolve o seu problema e quiser colocar uma questão, temos a nossa comunidade de apoio à espera de o ajudar em @FirefoxSupport no Twitter, /r/firefox no Reddit.

Pesquisar no apoio

Evite burlas no apoio. Nunca iremos solicitar que telefone ou envie uma mensagem de texto para um número de telefone ou que partilhe informações pessoais. Por favor, reporte atividades suspeitas utilizando a opção "Reportar abuso".

Saber mais

Our AJAX app intercepts F9 to provide context sensitive help. It works in IE7+, Chrome, Safari and Opera, but not in Firefox. Help!

  • 4 respostas
  • 2 têm este problema
  • 2 visualizações
  • Última resposta por lrirwin

more options

We researched IE, Firefox, Chrome, Safari and Opera - looking for a common function key that was unused to utilize for our app's context help key - and settled on the F9 key. Is there a way to ensure that the F9 key-press can be passed to the page -- it appears to do nothing in Firefox, but is not passed to the page. -- Thanks!

We researched IE, Firefox, Chrome, Safari and Opera - looking for a common function key that was unused to utilize for our app's context help key - and settled on the F9 key. Is there a way to ensure that the F9 key-press can be passed to the page -- it appears to do nothing in Firefox, but is not passed to the page. -- Thanks!

Solução escolhida

Firefox does not populate window.event like IE does. It never has. Modern browsers can pass the event object from the inline handler. Here's an example. I don't know whether older browsers support this (it works in IE8):

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>Test F9 keydown inline handler</title>
</head>
<body>
<p>Try F9<br><input type="text" name="textinput" size="25" value="sample value" onkeydown="keys(event,100)"></p>
<script type="text/javascript">
function keys(evt, arg){
  if (evt.which == 120 || evt.keyCode == 120){ // F9 key
    alert("Function passed: "+arg);
  }
  return false;
}
</script>
</body>
</html>
Ler esta resposta no contexto 👍 1

Todas as respostas (4)

more options

For some reason I can't recall, I have a page with a script that detects F9 and Shift+F9 using the keyup event. It works for me in Firefox 21 on Windows 7 -- I can't vouch for "IceWeasel/3.5.16" which is entirely unfamiliar to me...

If you drop this into a page, does it work on your Firefox?

 function keys(key){
   if (!key) {
     key = window.event;
     key.which = key.keyCode;
   }
   if (key.which == 120){ // F9 key
     if (key.shiftKey){
       alert("Shift+F9 pressed!");
     } else {
       alert("F9 pressed without Shift!");
     }
   }
   return false;
 }
 document.onkeyup = keys;
 document.body.focus();

If the IceWeasel detection is incorrect, see: How to reset the default user agent on Firefox.

more options

Thanks jscher2000,

The function you provided, when added to out standard table maintenance html, traps the keypress - without even referencing it anywhere! But, I'm still having trouble getting it to work within a function referenced by the onkeydown property of an element...

Here is the code we have working with other browsers to pop-up contextual help...

The function: function checkKeydown(fnr) {

 // Get Field Specs String from fspecs array
 fhelp = fspecs[fnr];
 // if (window.event.keyCode==120) alert('Caught F9 keypress');
 if (window.event.keyCode==120) create_HelpWindow(fhelp);

}

This is the snippet where we are dynamically building input boxes and we provide the field number as a pointer into the field specifications array: inputline+=' onkeydown="checkKeydown(\+ fnr + '\')"'

So, when a user has the focus in a specific input box, they press the F9 key and a pop-up box containing help about that specific field is displayed... But that approach it isn't working in Firefox...

more options

Solução escolhida

Firefox does not populate window.event like IE does. It never has. Modern browsers can pass the event object from the inline handler. Here's an example. I don't know whether older browsers support this (it works in IE8):

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>Test F9 keydown inline handler</title>
</head>
<body>
<p>Try F9<br><input type="text" name="textinput" size="25" value="sample value" onkeydown="keys(event,100)"></p>
<script type="text/javascript">
function keys(evt, arg){
  if (evt.which == 120 || evt.keyCode == 120){ // F9 key
    alert("Function passed: "+arg);
  }
  return false;
}
</script>
</body>
</html>
more options

Thank you for the solution! It works! - (in all the browsers)...