2

ContextMenu event doesn't work at cell phones? I use simple addEventListener("contextmenu", handler). It fires in Chrome Dev Tools, but doesn't fire in real cell phones. I tried it in Android and Windows Phone.

How to make it work?

Amal Dev
  • 1,938
  • 1
  • 14
  • 26
splash27
  • 2,057
  • 6
  • 26
  • 49

1 Answers1

0

What version of Chrome / Browser on Android and which version of Windows Phone are you using?

It may be worth adjusting your code to see if the document.addEventListener function is defined, if not then fallback to the older 'attachEvent' function.

Try this:

if (document.addEventListener) {
        document.addEventListener('contextmenu', function(e) {
        // handler
        }, false);
    } else {
        document.attachEvent('oncontextmenu', function() {
         //handler
        });
    }

Also, what is it you are trying to achieve by overwriting the default context menu behaviour?

When you say '...doesn't fire at real cell phones', does the document.addEventListener line not get hit, or does your handler function not execute correctly. Can you post your handle function code?

Jonathan Smith
  • 2,390
  • 1
  • 34
  • 60
  • @jonnyknowsbest, I use code that you're listed above to attach the handler. I tried it in Android 5 and Windows Phone 8.1 (Mobile IE11). In real devices the handler will be never launched (even if I put only an alert inside). As I know, to trigger the contextmenu, I need to perform the long tap. I do this, but nothing happens. – splash27 May 21 '15 at 09:42
  • Currenlty oncontextmenu is not supported for mobiles, thats why it wont fire. You should implement like @JonathanSmith said the longtap event by your own or use plugins – Miguel Aug 23 '17 at 12:17