Reputation: 5932
I have successfully implemented UIWebView Search text, Now i want to navigate through all the next occurrence and previous, Can any one suggest something in UIWebView. help greatly appreciated.
Thanks a lot
Upvotes: 0
Views: 415
Reputation: 3285
I was able to achieve the result using this javascript function
function goNext(){
jump(1);
}
function goPrev(){
jump(-1);
}
function jump(nextOrPrev){
prevSelected = currSelected;
currSelected = currSelected + nextOrPrev;
if (currSelected < 0){
currSelected = uiWebview_SearchResultCount + currSelected;
}
if (currSelected >= uiWebview_SearchResultCount){
currSelected = currSelected - uiWebview_SearchResultCount;
}
prevEl = document.getElementsByClassName("uiWebviewHighlight")[prevSelected];
if (prevEl){
prevEl.style.backgroundColor="yellow";
}
el = document.getElementsByClassName("uiWebviewHighlight")[currSelected];
el.style.backgroundColor="green";
el.scrollIntoView(true);
}
Do initialise currSelected=-1 in the beginning of your search function before element comparison, which should be something like this
if (element) {
if (element.nodeType == 3) { //your code} }
Upvotes: 1