jeudi 5 mai 2016

What is the mobile support for the oncontextmenu event? Or is there a way to detect if it is supported?

I'm working on a web application when right clicking on certain critical elements, it open a small contextual menu.

This works greats by listening to the oncontextmenu event.

Now on mobile, I want to open that menu by doing a long press on the element.

I was pretty surprised to see that this was already working on my android phone (using google chrome)! The context menu event gets fired after a long press on the element, and my little custom menu opens up, great.

Except it doesn't work on iphone. And no google search was able to tell me what exactly is the support for that event on mobile browsers?

So now I'm going to manually manage that behavior, which is simple enough, however, I'd like to only manage it manually for devices that don't support the oncontextmenu event. The reason is simply that if I manage it manually, I'm going to put a fixed delay for the long press detection, and that delay might not be consistent with the rest of the OS, it might be a bit longer or shorter than what the user is used to, while the oncontextmenu event is more likely to use some default system value for that.

However I currently have no luck in detecting whether the browser supports the event. On iphones, it is definitely not fired after a long press, however, the following line is true:

'oncontextmenu' in document.documentElement

So I currently have no luck in detecting whether or not that event is supported. Any help appreciated.




Aucun commentaire:

Enregistrer un commentaire