Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the selected text of a UIWebView

I'm trying to access the currently selected text in a UIWebView using the following line of code:

NSString *highlighted = [_webView stringByEvaluatingJavaScriptFromString:@"window.getSelection();"];

But it only returns an emtpy string. Any ideas about what I'm missing?

like image 216
fabian789 Avatar asked Feb 20 '23 02:02

fabian789


1 Answers

Try with this :

NSString * highlighted = [_webView stringByEvaluatingJavaScriptFromString:@"window.getSelection().toString()"];
like image 109
Maulik Avatar answered Feb 26 '23 21:02

Maulik