Home:ALL Converter>How do I disable default text selection behavior in a WKWebView

How do I disable default text selection behavior in a WKWebView

Ask Time:2015-10-01T03:53:19         Author:Jed Grant

Json Formatter

I have an app that loads a WkWebView, in that WebView there is JavaScript that is triggered when a text range is selected within the content. That script displays a HTML control on the page.

The problem occurs when the IOS menu (copy/define/share) shows up.

Problem 1

When the text is selected (long press) the HTML control is displayed. When you lift your finger from the screen, the IOS copy/define thing shows up, and the HTML control disappears. Adjusting the text range with the UI controls brings the HTML control back.

Desired behavior:

The IOS "menu" whatever it is actually called, is not necessary and I dont want it to be displayed. I also do not want the HTML control to go away, but I don't know what IOS is doing to make it happen. On the HTML page itself, clicking anywhere but the action button removes the selection and the HTML control. How do I disable this behavior?

Problem 2

Attempting to adjust the text selection range with the ui control at the end of the selection sometimes results in everything prior to the endpoint ui control to be selected.

Desire behavior:

For it not to do this. How to I prevent it from moving the side of the selection control that I am not touching?

Author:Jed Grant,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32874496/how-do-i-disable-default-text-selection-behavior-in-a-wkwebview
yy