5

I've written a web-app in HTML and Javascript for iPhone and Android which involves the dragging and dropping images.

You initiate the drag by holding your finger over the image for about a second. However, Android then pops up the message giving me the option to save the image, set it as wallpaper etc.

How can I prevent Android from doing this? Is there a metatag I can use? Some javascript?

user385990
  • 121
  • 1
  • 5

3 Answers3

3

Use this event:

            $(document).on('contextmenu', function (e) {
                // stop long touch hold from poping up context menus
                return false;
            });
Perry
  • 109
  • 10
2

Javascript has a function to prevent the default action of a browser for the event in question.

In your javascript try:

event.preventDefault();

See: https://developer.mozilla.org/en/DOM/event.preventDefault

Mechlar
  • 4,946
  • 12
  • 58
  • 83
  • 1
    To what event though? Nothing seems to fire until you pick your finger up. – user385990 Aug 13 '10 at 22:31
  • How are you assigning the mouseup/click/longpress event? That is where you define it. All user specified function attached to events will fire before the browsers. In other words, putting event.preventDefault(); in your function for your long press event should fire before androids function. Can we see a little more code? – Mechlar Aug 13 '10 at 22:48
  • All I want is so that when you press and hold on an image the Android dialog doesn't popup. – user385990 Aug 14 '10 at 00:10
  • ...and as far as I can see there is no longpress event. – user385990 Aug 14 '10 at 00:10
  • 1
    AFAIK you have to preventDefault in the touchstart handler to block the press. – James Baker Mar 30 '11 at 20:09
  • Not touchstart, that will also block the custom (drag) action. – Redzarf Mar 02 '17 at 18:48
-1

In your activity that shows the webview, try extending GestureDetector.SimpleOnGestureListener. Then override the onLongPress(MotionEvent e) method and doing nothing.

If that doesn't work, you might have to create a custom webview that inherets from webview and overrides onLongPress there.

Or maybe you could try


WebView wv =(WebView) findViewById()
wv.setClickable(false)

Falmarri
  • 47,727
  • 41
  • 151
  • 191
  • It's a webpage, not an Android App. – user385990 Aug 16 '10 at 16:06
  • Oh, I misunderstood. I thought you were writing an android app to interface with your web app. I'm not sure you're going to be able to prevent android from longpressing like that. – Falmarri Aug 16 '10 at 17:11