event.button
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);">
Alla svar (2)
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.
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