I need jQuery $(document).on("mousedown", "... work if I press alt and. For example the left or right mouse button, (maybe either shift + mouse button , or ctrl + mouse button ). .. In manifest.json, I can’t specify only alt ... Also, the problem is that a new tab or window opens to the shift / ctrl + mouse Left button event.

How to either cancel the launch of a new window or tab, or make an event on alt + mouse left button ? With pressed Alt jquery event does not work (....

    1 answer 1

    Variant # 1 - use the MouseEvent.altKey property, which determines whether or not the alt key is pressed and returns true or false respectively:

     $(document).on('mousedown', function(e) { if (e.altKey) { console.log('alt+mouse'); } else { console.log('mouse'); } }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

    Option # 2 - use a boolean flag to determine if the alt key is pressed:

     var altPress = false; $(document).on('keydown', function(e) { if (e.keyCode == 18) { altPress = true; } }).on('keyup', function(e) { if (e.keyCode == 18) { altPress = false; } }); $(document).on('mousedown', function() { if (altPress) { console.log('alt+mouse'); } else { console.log('mouse'); } }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

    • Does not work = (just mouse- works. - Achive Archive
    • @AchiveArchive When you press alt + lkm everything works fine - Cheg
    • and on this page, in any browser, does not work with alt + LKM, - Achive Archive
    • @AchiveArchive can you press the wrong button instead of alt? - Cheg