Organizational Research By

Surprising Reserch Topic

disabling the context menu on long taps on android

disabling the context menu on long taps on android  using -'javascript,android,mobile-webkit'

I would like to disable the context menu that appears after a long tap (touch and hold) on images in my web application. I've seen posts with different ideas how to do it, but none of them seem to work for me.

Is there a way to do this on Android via HTML/CSS/Javascript?

asked Sep 15, 2015 by VelDSEG
0 votes

Related Hot Questions

6 Answers

0 votes

This should work on 1.6 or later (if I recall correctly). I don't believe there's a workaround for 1.5 or earlier.

" width="400">

answered Sep 15, 2015 by RosWales
0 votes

I use the complete example by Nurik but the the element (an input image in my page) was disable for the click too.

I change the original line by this:

original line:

node.ontouchstart = absorbEvent_;

my change:

node.ontouchstart = node.onclick;

with this approuch i disable the pop-up save image menu on logpress but keep the click event.

I´m testing on a 7" tablet with Android 2.2 under a Dolphin HD browser and works fine!

answered Sep 15, 2015 by BobExc
0 votes

The context menu has its own event. You just need to catch it and stop it from propagating.

window.oncontextmenu = function(event) {
     return false;
answered Sep 15, 2015 by JefONI
0 votes

For me, absorbing all the events was not an option since I wanted to disable long press downloads while still allowing the user to zoom and pan on the image. I was able to solve this with css and html only by layering a "shield" div on top of the image like so:

img { max-width: 100%; } .shield { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 1; }

Hope this helps someone!

answered Sep 15, 2015 by ValorieMatti
0 votes

Capture the onContextMenu event, and return false in the event handler.

You can also capture the click event and check which mouse button fired the event with event.button, in some browsers anyway.

answered Sep 15, 2015 by ElvisDietric
0 votes

Through raw javascript there are no events that get called for the context menu. Perhaps in the Java world there is something... There are actually several issues regarding javascript events (such as focus not working right) in the Android webkit.

answered Sep 15, 2015 by TimothyEverh