禁用长水龙头在Android上的上下文菜单 [英] Disabling the context menu on long taps on Android

查看:139
本文介绍了禁用长水龙头在Android上的上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想禁用长按(触摸并按住)在我的Web应用程序中的图像后出现的上下文菜单。我已经看到了不同的想法的帖子如何做到这一点,但没有人似乎为我工作。

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.

有没有办法通过HTML做到这一点在Android / CSS / Javascript的?

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

推荐答案

这应该在1.6或更高版本(如果我没有记错)。我不相信有一个变通方法1.5或更早版本。

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.

<!DOCTYPE html>
<html>
<head>
  <script>
    function absorbEvent_(event) {
      var e = event || window.event;
      e.preventDefault && e.preventDefault();
      e.stopPropagation && e.stopPropagation();
      e.cancelBubble = true;
      e.returnValue = false;
      return false;
    }

    function preventLongPressMenu(node) {
      node.ontouchstart = absorbEvent_;
      node.ontouchmove = absorbEvent_;
      node.ontouchend = absorbEvent_;
      node.ontouchcancel = absorbEvent_;
    }

    function init() {
      preventLongPressMenu(document.getElementById('theimage'));
    }
  </script>
</head>
<body onload="init()">
  <img id="theimage" src="http://www.google.com/logos/arthurboyd2010-hp.jpg" width="400">
</body>
</html>

这篇关于禁用长水龙头在Android上的上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆