0

Is there a way of changing the scroll position of a UIWebView based on the current URL?

For example:

if (webView = thisURL) {
webView scrollPosition = ...
}
elseif (webView = thisURL) {
webView scrollPosition = ...
}

Thanks

Stickerbox
  • 141
  • 1
  • 12
  • Related: [How to set content offset and content size in a UIWebView](http://stackoverflow.com/questions/3525256/how-to-set-content-offset-and-content-size-in-a-uiwebview) – iDev Jan 18 '13 at 22:54
  • possible duplicate of [how to set scroll position on uiwebview](http://stackoverflow.com/questions/8470991/how-to-set-scroll-position-on-uiwebview) – mmmmmm Jan 19 '13 at 09:10
  • Webview has a property called scrollView.Change the offset of the scrollview like; webview.scrollView.contentOffset = CGPointMake(100, 0) – Sandeep Jan 19 '13 at 10:55

1 Answers1

1

Implement the UIWebViewDelegate, then make something like this:

-(void) webViewDidFinishLoad:(UIWebView *)webView{
    NSString *currentURL = webView.request.URL.absoluteString;
    if([currentURL isEqualToString:@"http://www.foo.com/uri"])
    [webView stringByEvaluatingJavaScriptFromString:@"scrollTo(100,100);"];
}

It catches the curren url displayed in the Web View, then it compares to another url and if the comparison returns true, the current webview fires a javascript calling the scrollTo() function.

hyunkeln
  • 429
  • 2
  • 9