Van*_*nel 2 javascript cocoa-touch uiwebview ios
我正在开发一个带有最新SDK和XCode 4.2的iOS应用程序.
我想在UIWebview中搜索文本并滚动到找到的第一个文本.
我正在使用本教程查找文本:http://zaldzbugz.posterous.com/how-to-search-a-string-inside-uiwebview
如何滚动到找到的第一个文本?
我们一步一步走吧.
突出
您使用的代码包含以下代码段.
var span = document.createElement("span");
var text = document.createTextNode(value.substr(idx,keyword.length));
span.appendChild(text);
span.setAttribute("class","uiWebviewHighlight");
span.style.backgroundColor="black";
span.style.color="white";
Run Code Online (Sandbox Code Playgroud)
我们需要一个id到跨度移动.所以添加id如下,
var span = document.createElement("span");
var text = document.createTextNode(value.substr(idx,keyword.length));
span.appendChild(text);
span.setAttribute("id","SEARCH WORD");
span.setAttribute("class","uiWebviewHighlight");
span.style.backgroundColor="black";
span.style.color="white";
Run Code Online (Sandbox Code Playgroud)
移至第一次出现.
使用'Webview didload'中的以下javascript移动到第一次出现.
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementById('SEARCH WORD').scrollIntoView()];
Run Code Online (Sandbox Code Playgroud)
希望这是有帮助的.
| 归档时间: |
|
| 查看次数: |
3545 次 |
| 最近记录: |