防止在 iOS Web 应用程序中复制图像

发布于 2024-10-31 12:03:35 字数 312 浏览 6 评论 0原文

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

Is there a way of preventing the menu that appears when you hold down a finger on an image on an iPad or iPhone web application. I am creating a remote control and I use the ontouchstart and ontouchend built in functions to create my "ontouchhold" function that I implemented. That function uses the ontouchstart and ontouchend built in functions to send IR signals via my computer which is acting as the server meanwhile the user is holding down its finger against an image (the ontouchend function will clear the interval). The only problem is that if the user holds its finger to long then the javaScript function ontouchhold that I implemented stops working because a menu pops up asking the user if he wants to copy/save the image. It will be nice if I could prevent this menu from appearing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

生活了然无味 2024-11-07 12:03:35

您可以使用:

-webkit-user-select: none;

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

You can use:

-webkit-user-select: none;

This property makes the html elements not be not selectable and thus prevents that copy behaviour of iphone

划一舟意中人 2024-11-07 12:03:35

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

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

-webkit-touch-callout: none; seems to do the trick of only preventing the copy/save dialog from opening without disabling any other events.

pointer-events: none; will also prevent the copy/save dialog but will also prevent any other dependent events attached to the image

音栖息无 2024-11-07 12:03:35

您可以添加 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();
}

但它也会阻止在滑动事件开始时滚动这个元素。

You can add a preventDefault() to the element, which prevents the copy menu:

// 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();
}

But it also prevents the scrolling when the swipe event was started on this element.

小巷里的女流氓 2024-11-07 12:03:35

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

I don't know about iOS or mobile phones: but if you make the image a background image, it doesn't usually give you the option to save .....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文