views:

629

answers:

3

I have a UIWebView with html data loaded in it
Is it possible to use javascript to search for text in this view?
Thanks for any answers

A: 

You could just load the HTML into a string and just search fo a substring of that string using cocoa touch.

zPesk
But if I did that, would it be possible to have the UIWebView scroll to the location of that text?
nazgul42
+1  A: 

You can search using javascript to find the text. To run the javascript, you would use:

[webView stringByEvaluatingJavaScriptFromString:@"/* script here */"];

I would then use the JavaScript scroll to as it's hard to calculate how the "pixel" location inside the webview relates to the pixel location outside.

The following links may be useful to help you write the JavaScript:

Example find script

And try prototype's scrollTo code (I'm new so can't link here: www.prototypejs.org/api/element/scrollto )

Benjie Gillam
A: 

Sorry I was checking the Example find script page but somehow can't get it. Could you please provide more details? I was trying to use simple window.find() but the result is only true/false which doesn't help much, since I want to scroll to found position. Thx

BobC