-1

I am trying to disable long press on my WKWebView as it allows to drag and drop of urls which is unwanted on my side. Just to clarify I don't want to disable the WKActionSheet but just the drag & drop feature of the links.

I tried:

webView.allowsLinkPreview = false

and

webView.evaluateJavaScript("document.body.style.webkitTouchCallout='none';")

but these does not seem to have any effect. Anybody have an idea? My app has minimum target iOS 15.

burnsi
  • 6,194
  • 13
  • 17
  • 27
Rascal
  • 1

1 Answers1

0

You can disable the selection on long press by setting a property on WKPreferences to false. Configure the WKWebView like you see below

func configureWebView() {
    let webConfiguration = WKWebViewConfiguration()
    webConfiguration.preferences.isTextInteractionEnabled = false
    webView = WKWebView(frame: .zero, configuration: webConfiguration)
    webView.uiDelegate = self
}
  • Thanks for the help but unfortunately doesn't work. This one disables the interaction with all the text so the user can't copy and paste the text etc. which I want to keep enabled. And long press/dragging on the links is still enabled. – Rascal Jan 11 '23 at 10:57