在 WKWebView 中禁用图像选择

发布于 2025-01-12 23:48:29 字数 308 浏览 4 评论 0原文

我使用 WKWebView 在我的应用程序中显示 Web 内容。我想让内容尽可能地让人感觉本土化。

我已经将此 CSS 添加到 WKWebView 中加载的网站中:

* {
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

不过,当长时间点击图像时,可以“选择并移动它们”。

我怎样才能防止这种情况发生?

附: 在 iOS 15.1 上,当点击文本时,会出现文本放大镜。 iOS 15.3.1 中不会发生这种情况。

I use a WKWebView to display web content in my app. I want to make the content to feel as native as possible.

I've already added this CSS to the web site loaded in the WKWebView:

* {
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

Still, when long tapping on images, they can be "selected and moved around".

How can I prevent this?

PS:
On iOS 15.1 when log tapping on text, the text magnification glass appears. This doesn't happen in iOS 15.3.1.

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

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

发布评论

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

评论(1

夜光 2025-01-19 23:48:29

您可以通过两种方式做到这一点(在 iOS 15.5 上测试):

1:CSS

img {
    user-drag: none;    
    -webkit-user-drag: none;    
}

2:HTML

<img src = "image.png" alt = "image" draggable = "false" />

You can do that in two ways (tested on iOS 15.5):

1: CSS

img {
    user-drag: none;    
    -webkit-user-drag: none;    
}

2: HTML

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