• 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:

  • Check if the provided value is of the specified type
  • Find last n matches
  • Perform a shallow merge of two or more objects
  • Remove an attribute from an element

Primary Sidebar

FREE UPDATES!

Get the latest updates in your inbox for FREE!

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2023 JavaScriptSource.com

  • About
  • Privacy Policy
  • Submit
  • FAQ
  • Jobs For Developers
  • Contact Us