使用Javascript跳转到UIWebView中的search结果

我已经build立了与JavaScript的uiwebviewsearch工作很好,但我希望能够跳转到search结果中的下一个发现的单词。 我已经成功地通过使用此代码创build视图以滚动到第一个实例:

if (uiWebview_SearchResultCount == 1) { var desiredHeight = span.offsetTop - 140; window.scrollTo(0,desiredHeight); } 

我怎么能得到这个searchresultcount更新到下一个find的结果(比如说,2,3,4,5等),当用户按下button在应用程序? 提前致谢。

我能够在webview中使用这个javascript做基本相同的事情:

 <script type="text/javascript"> var max = 100; function goToNext() { var hash = String(document.location.hash); if (hash && hash.indexOf(/hl/)) { var newh = Number(hash.replace("#hl","")); (newh > max-1) ? newh = 0 : void(null); document.location.hash = "#hl" + String(newh-1); } else { document.location.hash = "hl1"; } } </script> 

然后用这样的IBAction发送这个JavaScript调用:

 - (IBAction)next:(id)sender { [animalDesciption stringByEvaluatingJavaScriptFromString:@"goToNext()"]; } 

你的意思是你的应用程序中的本地button,如UIButton? 在这种情况下,你可以使用stringByEvaluatingJavaScriptFromString:在你的UIWebView中执行一些JavaScript。 你可以像这样做button的处理程序:

 - (void)buttonPressedAction:(id)sender { NSString * js = @"uiWebview_SearchResultCount++;"; [yourUIWebView stringByEvaluatingJavaScriptFromString: js]; } 

用适当的行调用这个函数?

 function scrollToDesiredHeight(row) { var desiredHeight = span.offsetTop - 140; window.scrollTo(0,row * desiredHeight); } 

这对你有用吗?