3

有没有办法防止在 iPad 或 iPhone Web 应用程序上按住手指时出现菜单。我正在创建一个遥控器,我使用 ontouchstart 和 ontouchend 内置函数来创建我实现的“ontouchhold”函数。该函数使用 ontouchstart 和 ontouchend 内置函数通过充当服务器的计算机发送 IR 信号,同时用户将手指按住图像(ontouchend 函数将清除间隔)。唯一的问题是,如果用户将手指握得太长,那么我实现的 javaScript 函数 ontouchhold 将停止工作,因为会弹出一个菜单,询问用户是否要复制/保存图像。如果我能阻止这个菜单出现,那就太好了。

4

4 回答 4

5

您可以使用:

-webkit-user-select: none;

此属性使 html 元素不可选择,从而防止 iphone 的复制行为

于 2011-07-07T12:03:07.310 回答
2

-webkit-touch-callout: none;似乎只阻止打开复制/保存对话框而不禁用任何其他事件的技巧。

pointer-events: none;还将阻止复制/保存对话框,但还将阻止附加到图像的任何其他相关事件

于 2014-01-30T18:08:57.397 回答
1

您可以将 a 添加preventDefault()到元素中,以防止复制菜单:

// HTML
<img scr="screenshot.jpg" id="dontshowcopy" />

// JS
element = document.getElementById('dontshowcopy');

element.addEventListener("touchstart",   preventCopy, false); // simple touch events
element.addEventListener("gesturestart", preventCopy, false); // events with more than one finger

function preventCopy(event) {
    event.preventDefault();
}

但它也阻止了在此元素上启动 swipe 事件时的滚动。

于 2011-05-24T10:51:31.207 回答
0

我不知道iOS或手机:但是如果您将图像设置为背景图像,它通常不会为您提供保存选项.....

于 2011-04-11T01:47:40.857 回答