Is right click a Javascript event?

后端 未结 18 2388
南笙
南笙 2020-11-22 10:02

Is right click a Javascript event? If so, how do I use it?

18条回答
  •  暖寄归人
    2020-11-22 10:31

    To handle right click from the mouse, you can use the 'oncontextmenu' event. Below is an example:

     document.body.oncontextmenu=function(event) {
         alert(" Right click! ");
     };
    

    the above code alerts some text when right click is pressed. If you do not want the default menu of the browser to appear, you can add return false; At the end of the content of the function. Thanks.

提交回复
热议问题