I need to know, when a web page has completely been loaded by UIWebView. I mean, really completely, when all redirects are done and dynamically loaded content is ready. I tr
Here's a simplified version of @jasonjwwilliams answer.
#define JAVASCRIPT_TEST_VARIBLE @"window.IOSVariable"
#define JAVASCRIPT_TEST_FUNCTION @"IOSFunction"
#define LOAD_COMPLETED @"loaded"
// Put this in your init method
// In Javascript, first define the function, then attach it as a listener.
_javascriptListener = [NSString stringWithFormat:
@"function %@() {\
%@ = '%@';\
};\
window.addEventListener(\"load\", %@, false);",
JAVASCRIPT_TEST_FUNCTION, JAVASCRIPT_TEST_VARIBLE, LOAD_COMPLETED, JAVASCRIPT_TEST_FUNCTION];
// Then use this:
- (void)webViewDidFinishLoad:(UIWebView *)webView;
{
// Only want to attach the listener and function once.
if (_javascriptListener) {
[_webView stringByEvaluatingJavaScriptFromString:_javascriptListener];
_javascriptListener = nil;
}
if ([[webView stringByEvaluatingJavaScriptFromString:JAVASCRIPT_TEST_VARIBLE] isEqualToString:LOAD_COMPLETED]) {
NSLog(@"UIWebView object has fully loaded.");
}
}