有没有办法阻止在iPad或iPhone网络应用程序上按住手指时出现的菜单。我正在创建一个遥控器,我使用ontouchstart和ontouchend内置函数来创建我实现的“ontouchhold”功能。该功能使用ontouchstart和ontouchend内置函数通过我的计算机发送IR信号,该计算机充当服务器,同时用户用手指按住图像(ontouchend函数将清除间隔)。唯一的问题是,如果用户长时间握住手指,那么我实现的java脚本功能就会停止工作,因为会弹出一个菜单询问用户是否要复制/保存图像。如果我可以阻止此菜单出现,那就太好了。
答案 0 :(得分:5)
您可以使用:
-webkit-user-select: none;
此属性使得html元素不可选,因此可以防止iphone的复制行为
答案 1 :(得分:2)
-webkit-touch-callout: none;
似乎只是防止打开复制/保存对话框而不禁用任何其他事件。
pointer-events: none;
也会阻止复制/保存对话框,但也会阻止附加到图像的任何其他相关事件
答案 2 :(得分:1)
您可以在元素中添加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();
}
但是当它在此元素上启动滑动事件时,它也会阻止滚动。
答案 3 :(得分:0)
我不知道iOS或手机:但是如果你把图像作为背景图像,它通常不会给你保存的选择......