javascript - Firefox fires click event at the same time with contextmenu event -


next code logs fired events on window object (fiddle):

var logevent = (function() {  var count = 1,      timer = 0,      buffer = function() {          cleartimeout(timer)          timer = settimeout(function() {              count++          }, 30)      }  return function(type, e) {      buffer();      console.log(count + '. ------- ' + type + ' ------')      console.log('type:   ' + e.type)      console.log('button: ' + e.button)      console.log('detail: ' + e.detail)  }  })()  window.addeventlistener('click', function(e) {  logevent('click', e)  })  window.addeventlistener('contextmenu', function(e) {  logevent('contextmenu', e)  })
<body>  <div>      click here  </div>  </body>
if right click on body element example, i'll next log on console:

for firefox 54.0.1

  1. ------- click ------   type:   click   button: 2   detail: 1   1. ------- contextmenu ------   type:   contextmenu   button: 2   detail: 1 

for chrome 62.0.3165.0

  1. ------- contextmenu ------   type:   contextmenu   button: 2   detail: 0 

i don't know what's going on firefox, maybe browsers or operational systems configuration configured improperly. did have same problems, how can fix it?

it happens on firefox too.

it's registered bug, see https://bugzilla.mozilla.org/show_bug.cgi?id=184051

you can go around checking e.button value in click handler.

window.addeventlistener('click', function(e) {     //when e.button==2, it's right click, when 0, it's left click     logevent('click.' + e.button, e);     if(e.button===2){         //do context menu stuff     } }) 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -