• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Miscellaneous / Capture the right click event with JavaScript

Capture the right click event with JavaScript

Capture the right click event with JavaScript

Two ways to capture the right click on a mouse.

window.oncontextmenu = () => {
	console.log('right click');
	return false // cancel default menu
}

//or

window.addEventListener('contextmenu', ()=>{
	console.log('right click');
	return false // cancel default menu
},false)

Source

https://github.com/roeib/JavaScript-snippets#capture-the-right-click-event

Miscellaneous

Related Snippets:

  • Destructing variable assignment
  • Vanilla JS toggle
  • Combine two arrays using the spread operator
  • Optional Chaining to Prevent Crashes

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers