How to determine if iFrame has finished loading in UIWebView

In my application, I need to indicate when my web browsing will be completed. This is very easy to do if the content is html. However, the source of my content is javascript with an iFrame inside, this will call the finishedIoad UIWebView method, which is called several times. Anyway, can I check if the loading of the iframe is complete?

+7
javascript iphone iframe
May 14 '10 at 20:24
source share
3 answers

The only reliable method I found was to listen to three methods that talk about the start of the download, and that it completed the download (plus the equivalent for "failure") and manually checked the count for each.

i.e. something like:

int outstandingRequests; - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { outstandingRequests++; } - (void)webViewDidFinishLoad:(UIWebView *)webView { outstandingRequests--; if( outstandingRequests < 1 ) viewLoadingPleaseWait.hidden = TRUE; } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { outstandingRequests--; } 

I also usually had to overcome the didFail method - Apple is using it incorrectly to report that, for example, a YouTube player took control of a YouTube video. This is NOT a mistake, it is a "page has been loaded by another application."

eg.

 - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { outstandingRequests--; if( [error code] == NSURLErrorCancelled ) { NSLog(@"[%@] ...webView CANCELLED loading", [self class] ); } else if( [[error domain] isEqualToString:@"WebKitErrorDomain"] && [error code] == 204) { // no worries ... YouTube, iCal, or etc took over the page load } } 
+7
Nov 19 2018-10-19
source share

(If it is the same domain), you can call the function (in the parent) from the iframe.

 top.iFrameLoaded(); 
+1
Dec 02 '10 at 20:27
source share

To find out if a webView.isLoading , you can use webView.isLoading to check if all frames of the webView.isLoading are loaded. There is no count of the number of frames needed. Just check if isLoading true inside webViewDidFinishLoad:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html

0
Jun 29 '13 at 4:51 on
source share



All Articles