I have been reading up on this all day and simply cannot solve the problem. I am attempting to load a web page and after it is done loading automatically scroll it to a pre determined point. I have been reading tutorials such as this http://iphoneincubator.com/blog/windows-views/how-to-inject-javascript-functions-into-a-uiwebview and still no luck.
Here is my .m where the problem is occurring. I'm desperate please help! Also, it is telling me that my webViewDidFinishLoad is overwriting the instance variable but that shouldn't be a problem I believe
- (void)viewDidLoad {
[super viewDidLoad];
NSString *urlAddress = @"http://www.twitter.com/richrines";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
// Do any additional setup after loading the view from its nib.
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[webView stringByEvaluatingJavaScriptFromString:@"var script = document.createElement('script');"
"script.type = 'text/javascript';"
"script.text = \"function myFunction() { "
"window.scrollTo(100,100)"
"}\";"
"document.getElementsByTagName('head')[0].appendChild(script);"];
[webView stringByEvaluatingJavaScriptFromString:@"myFunction();"];
}
Why are you doing it in such a complicated manner? This should be all you need:
[webView stringByEvaluatingJavaScriptFromString:@"window.scrollTo(100,100)"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With