How can I search in an UIWebView?

不想你离开。 提交于 2019-12-30 03:34:10

问题


I need to perform search in an html page displayed in a UIWebView control. The functionality I need is something that Safari has, when you hit command/ctrl F for searching the document for some word and the program highlights the hits for you. Is there any easy solution for this problem?


回答1:


I know it's been a long time since you asked this question, but it's still a pretty common question people have so I put together a sample project in case anyone else is asking the same question. The project is a super simple app that loads an HTML file and can search and highlight any keyword. You can download the sample project here:

https://www.dropbox.com/s/jietctrvrtnec28/TheSearcher.zip?dl=0

Scott

Edit: changed link above as the old one had broken.




回答2:


You could do this with javascript. Check out the "Find in this page" bookmarklet: http://www.lifeclever.com/17-powerful-bookmarklets-for-your-iphone/

Something like that, combined with: http://developer.apple.com/iphone/library/documentation/uikit/reference/UIWebView_Class/Reference/Reference.html#//apple_ref/occ/instm/UIWebView/stringByEvaluatingJavaScriptFromString:

might do the trick.



来源:https://stackoverflow.com/questions/1004094/how-can-i-search-in-an-uiwebview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!