iosswiftwkwebviewwkwebviewconfiguration

Disable image selection in WKWebView


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.


Solution

  • 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" />