views:

346

answers:

1

For an iPhone app I was using window.scrollBy to scroll to the bottom of a page. The page is rendered in a UIWebView. This all worked fine untill sdk 3.0. It is documented that scrollBy is not supported in UIWebView anymore. Is there an handy javascript replacement for window.scrollBy?

A: 

Hi ,

You can use the following methods to solve your problem.

For getting the pageOffset:

int pageYOffset = [[webViewObj stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];

For getting the total scroll height of a webpage:

int scrollHeight = [[webViewObj stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"] intValue];

For scrolling the webpage to a particular offset:

[webViewObj stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.body.scrollTop = %d",scrollHeight ]];

Biranchi