JavaScript Reference/Event Handlers Reference/onContextMenu

Материал из Web эксперт
Перейти к: навигация, поиск

"onContextMenu" Example

    
<html>
<head>
<script language="JavaScript">
    function function2() {
        alert("This image is copyrighted") 
    }
</script>
</head>
<body oncontextmenu="function2()">
    <p>Right click in the image.</p>
    <img oncontextmenu="function2()" 
         src="http://www.wbex.ru/style/logo.png" 
         alt="" 
         width="99" 
         height="76">
</body>
</html>
If you want to prevent the user from opening the context menu, 
add the following code to the <body> element above:
oncontextmenu="function2(); return false;"



"onContextMenu" is applied to

+----------------+--------------------------------------------------------------+
| Applied_To     |<a>                             <address>                     |
|                |<applet>                        <area>                        |
|                |<b>                             <bdo>                         |
|                |<big>                           <blockquote>                  |
|                |<body>                          <button>                      |
|                |<caption>                       <center>                      |
|                |<cite>                          <code>                        |
|                |<custom>                        <dd>                          |
|                |<dfn>                           <dir>                         |
|                |<div>                           <dl>                          |
|                |document                        <dt>                          |
|                |<em>                            <embed>                       |
|                |<fieldset>                      <font>                        |
|                |<form>                          <hn>                          |
|                |<hr>                            <i>                           |
|                |<img>                           <input type="button">         |
|                |<input type="checkbox">         <input type="file">           |
|                |<inputtype="image">             <input type="password">       |
|                |<input type="radio">            <input type="reset">          |
|                |<input type="submit">           <input type="text">           |
|                |<kbd>                           <label>                       |
|                |<legend>                        <li>                          |
|                |<listing>                       <marquee>                     |
|                |<menu>                          <nobr>                        |
|                |<ol>                            <p>                           |
|                |<pre>                           <rt>                          |
|                |<ruby>                          <s>                           |
|                |<samp>                          <select>                      |
|                |<small>                         <span>                        |
|                |<strike>                        <strong>                      |
|                |<sub>                           <sup>                         |
|                |<table>                         <tbody>                       |
|                |<td>                            <textarea>                    |
|                |<tfoot>                         <th>                          |
|                |<thead>                         <tr>                          |
|                |<tt>                            <u>                           |
|                |<ul>                            <var>                         |
|                |<xmp>                                                         |
+----------------+--------------------------------------------------------------+



"onContextMenu" Properties

+----------------+--------------------------------------------------------------+
| Properties     |altKey                          altLeft                       |
|                |cancelBubble                    clientX                       |
|                |clientY                         ctrlKey                       |
|                |ctrlLeft                        offsetX                       |
|                |offsetY                         returnValue                   |
|                |screenX                         screenY                       |
|                |shiftKey                        shiftLeft                     |
|                |srcElement                      type                          |
|                |x                               y                             |
+----------------+--------------------------------------------------------------+



"onContextMenu" Syntax and Note

Note:
    
This event fires when the user opens the context menu by clicking 
the right mouse button.