Jump through search results in UIWebView with Javascript

喜夏-厌秋 提交于 2019-12-06 15:05:20

I was able to do basically the same thing with this javascript in the webview:

<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>

Then sending this JavaScript call with my IBAction like this:

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

Do you mean a native button in your app such as a UIButton? In that case, you can use stringByEvaluatingJavaScriptFromString: to execute some JavaScript in your UIWebView. You could do something like this as the handler for your button:

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

call this function with the appropriate row?

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

Does this work for you?

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