When you long press a word on a WKWebView webpage, you will select it, and system will popup a menu to let you share/copy/lookup it so on. This is the iOS default behavior.
So my question is, how do you programmatically get a word from indicated point (CGPoint) on the WKWebView webpage?
Or, how do you programmatically select a word on WKWebView webpage without long press?
Any advice appreciated!
First you must convert the point to the scrollview's coordinate system using convertPoint:toView:. You can use this point in a Javascript (with jQuery) function which will search the DOM node at this point:
function(inX, inY) {
var theWindow = $(window);
var theElement = document.elementFromPoint(
inX - theWindow.scrollLeft(), inY - theWindow.scrollTop());
return theElement == null ? null : theElement.textContent;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With