Jquery :: Disable Right Click

Created For: http://stackoverflow.com/q/10864249/352449

by juberti

HTML

<canvas id="myCanvas" width="200" height="100">
  Your browser does not support the canvas element.
</canvas>

<img src="http://db.tt/oM60W6cH" alt="bubu">
<div id="a">
<iframe id="b" src="http://www.google.com" width="400" height="400" style="pointer-events:none;"></iframe>
</div>

CSS

canvas {
    border:1px solid #D9D9D9;
    background-color: #F2F2F2;
}
#a {
  visibility: hidden;
    z-index: 1;
    position:absolute;
  left: 0px;
  top: 0px;
}
#b {
  

}

JavaScript

/*$('body').on('contextmenu', '#myCanvas', (e) => {
  //e.stopPropagation();
  e.preventDefault();//false;
});
*/


function handleEvent(eventType, e) {
  console.log(eventType + e);
  e.stopPropagation();
  e.preventDefault();
  return false
}


function addListener(eventType) {
 if (true) {
      // Use the options object to specify passive as false for all listeners.
      // Technically this should not affect keyboard behaviors (as of the time
      // of writing), but mouse and touch events specifically must not be
      // passive.
      window.addEventListener(
          eventType, (e) => handleEvent(eventType, e), {
            capture: true,
            once: false,
            passive: false,
          });
    } else {
      window.addEventListener(
          eventType, (e) => handleEvent(eventType, e), true);
    }
}


addListener("click");
addListener("contextmenu");
addListener("mousedown");
addListener("mouseup");