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?
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.
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.
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