Yes, I know UIWebView has didFinishedLoad & didStartLoad delegate.
However, the didFinishedLoad does not mean the full completion. It may be called when one of the items that the UIWebView is finished loading. i.e., UIWebView may call this delegate several times while loading a single page.
So anyway can tell me how to check whether the UIWebView is fully loaded?
Thanks
J
I have poor experience with DOM but after some searching I found that the document.readyState is the great option.
From w3schools:
Definition and Usage The readyState property returns the (loading) status of the current document.
This property returns one of four values:
uninitialized - Has not started loading yet
loading - Is loading
interactive - Has loaded enough and the user can interact with it
complete - Fully loaded
So I'm using this to know when UIWebView has loaded the document:
- (void)readyState:(NSString *)str
{ NSLog(@"str:%@",str);
if ([str isEqualToString:@"complete"]||[str isEqualToString:@"interactive"]) {
NSLog(@"IT HAS BEEN DONE");
[pageLoadingActivityIndicator stopAnimating];
}
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//other code...
[self readyState:[browserWebView stringByEvaluatingJavaScriptFromString:@"document.readyState"]];
}
http://www.codingventures.com/2008/12/using-uiwebview-to-render-svg-files/ on Javascript communicating back with Objective-C code
Maybe use document location hash.
And add in the webview html body:
<body onload="document.location.hash='myapp:myobject:myfunction';">
I know its a little bit hacky but works. And it can be used in ajax based contents, because its up to you when you want to call your ready method. Or it can be used as a complete communication scheme.
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