I am using a webView to display text content, and I am trying to use javascript to highlight text that the user selects. This becomes possible when contentEditable = yes
, but that also brings up the keyboard whenever the user taps on any text.
How can I have the contentEditable = yes
, but not have the keyboard show up so that the text is editable?
EDIT: Here is the code I am using to do the highlighting
- (void)highlight {
NSString *currentColor = [webView stringByEvaluatingJavaScriptFromString:@"document.queryCommandValue('backColor')"];
if ([currentColor isEqualToString:@"rgb(255, 255, 0)"]) {
[webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('backColor', false, 'white')"];
} else {
[webView stringByEvaluatingJavaScriptFromString:@"document.execCommand('backColor', false, 'yellow')"];
}
}
I found it on this tutorial.