Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically enter 'selection mode' in a UIWebView?

I'm trying to create an iBooks like experience, where users can highlight text within a document. To do that, I'm using a UIWebView with my document in an HTML format.

I've figured out how to capture the initial selection highlight, but can't make it so the user can edit or change their highlight once made.

I'm hoping to pre-define a javascript Selection DOM Object with the Range of the highlight and then programmatically enter 'selection mode'. It seems that you can only enter selection mode by long-pressing on a piece of text, and then automatically creates the Selection DOM Object for you.

How do you programmatically enter selection mode with a UIWebView?

like image 349
Stephan Heilner Avatar asked Jun 06 '13 21:06

Stephan Heilner


2 Answers

Does the following SO question help?

Highlight text range using JavaScript

Or look at

https://code.google.com/p/rangy/

Rangy is a cross-browser JavaScript range and selection library.

like image 167
Uygar Y Avatar answered Nov 15 '22 14:11

Uygar Y


You can manipulate the web page by directly executing Javascript strings in it. There is a method:

- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)javascriptString

in UIWebView. This will execute arbitrary script in your page's DOM. Use this with some jQuery maybe you will be able to do that. So maybe you need to interact with your DOM heavily to emulate this.

like image 34
Maxthon Chan Avatar answered Nov 15 '22 14:11

Maxthon Chan