How to get the word in the specified location on WKWebView?

When you long press a word on the WKWebView web page, you select it and the system displays a menu so you can share / copy / search for it like that. This is the default behavior for iOS.

So my question is: how do you programmatically get a word from a specified point (CGPoint) on a WKWebView web page ?

Or, how do you programmatically select a word on a WKWebView webpage without a long press ?

Any advice appreciated!

+4
source share
1 answer

scrollview, convertPoint: toView:. Javascript ( jQuery), DOM node :

function(inX, inY) {
    var theWindow = $(window);
    var theElement = document.elementFromPoint(
        inX - theWindow.scrollLeft(), inY - theWindow.scrollTop());

    return theElement == null ? null : theElement.textContent;
}
+1

Source: https://habr.com/ru/post/1661414/


All Articles