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?
- How to create an HTML button that acts like a link
- Cannot set property InnerHTML of null [duplicate]
- Is there an upside down caret character?
- Prevent line-break of span element
- Disable Scrolling on Body
- Darken CSS background image?
- Alternative to iFrames with HTML5
- What is “X-Content-Type-Options=nosniff”?
- “.addEventListener is not a function” why does this error occur?
- Get checkbox value in jQuery
- Including external HTML file to another HTML file [duplicate]
- How can I override Bootstrap CSS styles?
- Can’t fix: ‘og:image’ property should be explicitly provided, even if a value can be inferred from other tags
- vertical-align with Bootstrap 3
- What is the difference between localStorage, sessionStorage, session and cookies?
- How to display Base64 images in HTML
- How do I align in my image to move it vertically up?(CSS,HTML)?
- How do I change the font color in an html table?
- How to change the text of a label?
- JavaScript – Count Number of Visitor for Website
- Using “×” word in html changes to ×
- How do I store an array in localStorage?
- How to embed an autoplaying YouTube video in an iframe?
- Cannot read property ‘style’ of undefined — Uncaught Type Error
- window.location.href doesn’t redirect
- How can I publish Word files to a WordPress blog without losing the footnotes?
- Javascript code inside “” in core WordPress files .php
- How can I set different html lang attribute for different countries?
- How to integrate my HTML and javascript into my child theme
- Ajaxify This Code
- parts of url disappear when using # inside href=”” [closed]
- Add Attribute to p Tag of Post Content
- Can’t save any WordPress post with the html tag in it
- Noscript not working as it should in wordpress site
- remove string: ‘custom content…’ from every page
- Whitespace Before Doctype
- html entities occur in the_excerpt used as meta description
- how to let users upload their custom cover image
- standard callback function for wp_list_comments
- How to replace a specific html tag in bulk?
- I need help implement a Javascript code into the PHP file
- Inserting code into a page just shows raw HTML
- dropdown does not work [closed]
- Moving from Microsoft Front Page 2003 to WordPress