mozilla

Compare Revisions

Event.button

Change Revisions

Revision 17643:

Revision 17643 by Sheppy on

Revision 17644:

Revision 17644 by berkerpeksag on

Title:
event.button
event.button
Slug:
DOM/event.button
DOM/event.button
Tags:
DOM, Gecko, "Gecko DOM Reference"
DOM, Gecko, "Gecko DOM Reference"
Content:

Revision 17643
Revision 17644
n26<span class="Apple-style-span" style="font-family: 'Courier New',n26var buttonCode = event.button;
> 'Andale Mono', monospace; font-size: 14px; white-space: pre; fon 
>t-weight: normal; line-height: normal;">var buttonCode = event.bu 
>tton;</span> 
n40      <strong>Note:</strong> This convention is not followed in In40      <strong>Note:</strong> This convention is not followed in I
>nternet Explorer: see <a class="external" href="http://www.quirks>nternet Explorer: See <a class="external" href="http://www.quirks
>mode.org/js/events_properties.html#button" title="http://www.quir>mode.org/js/events_properties.html#button" title="http://www.quir
>ksmode.org/js/events_properties.html#button">QuirksMode for detai>ksmode.org/js/events_properties.html#button">QuirksMode for detai
>ls</a>.>ls</a>.
n49&lt;script type="text/javascript"&gt;n49&lt;script&gt;
50var whichButton = function (e) {
51    // Handle different event models
52    var e = e || window.event;
53    var btnCode;
n51function whichButton(e)n55    if ('object' === typeof e) {
52{56        btnCode = e.button;
53  // Handle different event models
54  var e = e || window.event;
55  var btnCode;
n57  if ('object' == typeof e){n
58    btnCode = e.button;
59 
60    switch (btnCode){58        switch (btnCode) {
59            case 0:
61      case 0  : alert('Left button clicked');60                alert('Left button clicked.');
62                break;61            break;
62            case 1:
63      case 1  : alert('Middle button clicked');63                alert('Middle button clicked.');
64                break;64            break;
65            case 2:
65      case 2  : alert('Right button clicked');66                alert('Right button clicked.');
66                break;67            break;
68            default:
67      default : alert('Unexpected code: ' + btnCode);69                alert('Unexpected code: ' + btnCode);
70        }
n69  }n
n71 n
n74&lt;p onmouseup="whichButton(event);" oncontextmenu="event.prevenn75&lt;button onmouseup="whichButton(event);" oncontextmenu="event.p
>tDefault();"&gt;Click with mouse...&lt;/p&gt;>reventDefault();"&gt;Click with mouse...&lt;/button&gt;
75 
tt92    <h3>
93      Browser compatibility
94    </h3>
95    <p>
96      Based on Jan Wolter's <a class="external" href="http://unix
 >papa.com/js/mouse.html">JavaScript Madness: Mouse Events</a>.
97    </p>
98    <p>
99      {{ CompatibilityTable() }}
100    </p>
101    <div id="compat-desktop">
102      <table class="compat-table">
103        <tbody>
104          <tr>
105            <th>
106              Feature
107            </th>
108            <th>
109              Gecko
110            </th>
111            <th>
112              Webkit
113            </th>
114            <th>
115              Internet Explorer
116            </th>
117            <th>
118              Opera
119            </th>
120          </tr>
121          <tr>
122            <td>
123              Basic support
124            </td>
125            <td>
126              1
127            </td>
128            <td>
129              523
130            </td>
131            <td>
132              9
133            </td>
134            <td>
135              8
136            </td>
137          </tr>
138        </tbody>
139      </table>
140    </div>

Back to History