Get the App
SLTechnology News&Howtos  ›  Development  › 

How to hide the right button in javascript

Shulou Source: shulou.com Published: 2022-06-02 03:11:11 09月12日 Update

Javascript how to hide the right button, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Javascript hide the right button method: 1, open the corresponding code file; 2, use the "_ window.oncontextmenu=function (e) {e.preventDefault ();}" method to disable the right mouse button menu.

This article operating environment: Windows7 system, javascript1.8.5, Dell G3 computer.

How does javascript hide the right button?

Js sets or disables the right mouse button menu

The oncontextmenu event is triggered when the user clicks the right mouse button

Js disables the right mouse button menu

_ window.oncontextmenu=function (e) {/ / it is important to cancel the default browser with its own right button! E.preventDefault ();}

Js customize the right mouse button menu

Html prepare Custom menu item function 1 function 2 function 3 function 4 function 5css set menu item style # menu {width: 0; / * set to 0 hide Custom menu * / height: 125px; overflow: hidden; / * hide overflow element * / box-shadow: 0 1px 1px # 888 1px 1px 0 1px # ccc; position: absolute / * Custom menus are positioned relative to body elements * /} .menu {width: 130px; height: 25px; line-height: 25px; padding: 010px;} js controls the display and hiding of menus _ window.oncontextmenu=function (e) {/ / it is important to cancel the default browser with a right button! E.preventDefault (); / / get our custom right-click menu var menu=document.querySelector ("# menu"); / / locate menu.style.left=e.clientX+'px'; menu.style.top=e.clientY+'px'; / / change the width of the custom menu to show menu.style.width='100px'; menu.style.height='auto' according to the location of the mouse click in the event object } / / Click anywhere with the left mouse button to close the right-click menu _ window.onclick=function (e) {/ / the user triggers the click event to close it, because it is bound on the window and bubbles by the event, which will not affect the menu function document.querySelector ('# menu'). Style.height=0;} after reading the above, have you mastered how to hide the right button in javascript? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Menu mouse function event method important location element content more browser user problem location browsing helpless for this code reason for this Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft Shulou Technology macOS NVidia