Use the oncontextmenu
event.
Here’s an example:
<div oncontextmenu="javascript:alert('success!');return false;"> Lorem Ipsum </div>
And using event listeners (credit to rampion from a comment in 2011):
el.addEventListener('contextmenu', function(ev) { ev.preventDefault(); alert('success!'); return false; }, false);
Don’t forget to return false, otherwise the standard context menu will still pop up.
If you are going to use a function you’ve written rather than javascript:alert("Success!")
, remember to return false in BOTH the function AND the oncontextmenu
attribute.
Related Posts:
- How to make JavaScript execute after page load?
- jQuery equivalent of JavaScript’s addEventListener method
- Onclick javascript to make browser go back to previous page?
- How to make JavaScript execute after page load?
- How to make JavaScript execute after page load?
- Why onbeforeunload event is not firing
- Edit webpage with javascript trick – how to “unedit”?
- window.onload vs document.onload
- Automatically pausing html5 video as the ‘next’ button is pressed (javascript/ jquery)
- Is it possible to write data to file using only JavaScript?
- jQuery.click() vs onClick
- Remove CSS class from element with JavaScript (no jQuery) [duplicate]
- Is it possible to write data to file using only JavaScript?
- Set cookie and get cookie with JavaScript
- What is DOM Event delegation?
- Which is better: or
- Why is my Javascript not working?
- How can I get the values of data attributes in JavaScript code?
- Javascript: getElementById vs getElementsById (both works on different pages)
- What does on() in JavaScript do?
- mailto using javascript
- mailto using javascript
- Mailto using Javascript?
- How to change css property using javascript
- javascript close current window
- Fire ontextchanged() event of an asp:TextBox via Javascript
- I am trying to make a simple toggle button in javascript
- How to call a JavaScript function within an HTML body
- How to save user input into a variable in HTML and JavaScript
- Hiding a button in Javascript
- Show/hide ‘div’ using JavaScript
- Get HTML code using JavaScript with a URL
- Calculate percentage Javascript
- How to display image with JavaScript?
- Resize image with javascript canvas (smoothly)
- JavaScript function onhover in
- Check if an element contains a class in JavaScript?
- Hide element by class in pure Javascript
- How to play a mp3 using Javascript? [duplicate]
- mailto using javascript
- Function not defined javascript
- How to submit a form with JavaScript by clicking a link?
- How to call a REST web service API from JavaScript?
- Check a radio button with javascript
- Is it possible to append to innerHTML without destroying descendants’ event listeners?
- AppendChild() is not a function javascript
- How can I change an element’s class with JavaScript?
- JavaScript: Get image dimensions
- Why write script type=”text/javascript” when the mime type is set by the server?
- How to select an input element by value using javascript?
- javascript window.location in new tab
- Fire oninput event with jQuery
- How to create a hidden
in JavaScript?
- How do I programmatically set the value of a select box element using JavaScript?
- How to make HTML element resizable using pure Javascript?
- How do I clear the content of a div using JavaScript?
- Is HTML considered a programming language? [closed]
- Open source social media icons to download and use on website? [closed]
- How to make a monopoly board using css grid?
- How to add a browser tab icon (favicon) for a website?
- Redirect from an HTML page
- Redirect from an HTML page
- What is ' and why does Google search replace it with apostrophe?
- What’s the difference between ” ” and ” “?
- Should I use tag for icons instead of ? [closed]
- Open link in new tab or window [duplicate]
- Half circle with CSS (border, outline only)
- Line break in HTML with ‘\n’
- CSS calc width and height values
- Wait 5 seconds before executing next line
- Failed to load resource: the server responded with a status of 404 (Not Found)
- HTML encoding issues – “” character showing up instead of ” “
- How to horizontally center an element
- Center image using text-align center?
- Unblur content inside blurring background div
- Adding a favicon to a static HTML page
- Failed to load resource: the server responded with a status of 404 (Not Found)
- Failed to load resource: the server responded with a status of 404 (Not Found) css
- Maximum call stack size exceeded error
- How to properly use jsPDF library
- How do I link a JavaScript file to a HTML file?
- Can I use complex HTML with Twitter Bootstrap’s Tooltip?
- See answer keys in Google Form (quiz) source page?
- CSS Background Opacity [duplicate]
- Angular, image not found (GET 404)
- what do
- CSS Background Opacity [duplicate]
- reCAPTCHA ERROR: Invalid domain for site key
- Google Chrome Uncaught (in promise) DOMException while playing AUDIO
- Android WebView err_unknown_url_scheme
- How to make a word underline in Markdown
- Customize icon for “Add to home screen”
- How to create an HTML button that acts like a link
- What do < and > stand for?
- ChartJS beginAtZero, min, max doesn’t work
- How do I check whether a checkbox is checked in jQuery?
- how to fix : ” TypeError: Cannot read property ‘addEventListener’ of null”…?//
- Cannot set property InnerHTML of null [duplicate]
- ReferenceError: $ is not defined
- How to fix “Cannot read property ‘addEventListener’ of null” error [duplicate]