Where did you install Firefox from? Help Mozilla uncover 3rd party websites that offer problematic Firefox installation by taking part in our campaign. There will be swag, and you'll be featured in our blog if you manage to report at least 10 valid reports!

Шукати в статтях підтримки

Остерігайтеся нападів зловмисників. Mozilla ніколи не просить вас зателефонувати, надіслати номер телефону у повідомленні або поділитися з кимось особистими даними. Будь ласка, повідомте про підозрілі дії за допомогою меню “Повідомити про зловживання”

Learn More

Ця тема перенесена в архів. Якщо вам потрібна допомога, запитайте.

event.button

  • 2 відповіді
  • 1 має цю проблему
  • 2 перегляди
  • Остання відповідь від keithprice900533

more options

why does this not work in FF <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> <script> function mouseButton(e) { alert(event.button); } </script> <input name="Button" type="radio" value="1" onmousedown="mouseButton(this);">

why does this not work in FF <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script> function mouseButton(e) { alert(event.button); } </script> </head> <body> <input name="Button" type="radio" value="1" onmousedown="mouseButton(this);" /> </body> </html>

Усі відповіді (2)

more options

The short answer is, "because the event object is not defined." Unlike IE, Firefox doesn't attach events to the global window object. Instead, it is passed to the function. You could try something like this:


<!DOCTYPE html> <html> <head> <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> <script type="text/javascript"> function mouseButton(e){ if (!e) e = window.event; var tgt = (e.target) ? e.target : e.srcElement; if (e.which){ // not IE switch (e.button){ case 0: var btn = "left"; break; case 1: var btn = "middle"; break; case 2: var btn = "right"; } } else { // IE switch (e.button){ case 1: var btn = "left"; break; case 4: var btn = "middle"; break; case 2: var btn = "right"; } } alert(btn + " mouse button down on " + tgt.nodeName + "#" + tgt.id); } window.onload = function(){ document.getElementById("rad1").onmousedown = mouseButton; } </script> </head> <body> <p><input type="radio" name="button" value="1" id="rad1"></p> </body> </html>

Note: because different browsers return different values for e.button, I'm not sure this is 100% reliable. You probably can find better code for sorting out the button value.

more options

As you may have guessed what I needed was much more complex than this, but with your post I have been able to do what I needed, thank you very much for your help. All the best Keith