admin管理员组文章数量:1295314
In my app, I need a way to tell when my webview is finished loading. It is very easy to do that if content is html. However, my content source is javascript with iFrame inside, it will cause UIWebView finishedLoad method called several times. Is there anyway I can check to see if the iframe is finished loading?
In my app, I need a way to tell when my webview is finished loading. It is very easy to do that if content is html. However, my content source is javascript with iFrame inside, it will cause UIWebView finishedLoad method called several times. Is there anyway I can check to see if the iframe is finished loading?
Share asked May 14, 2010 at 20:24 David David 711 silver badge3 bronze badges3 Answers
Reset to default 7The only foolproof method I've found is to listen to the three methods that say it's about to start loading, and that it finished loading (plus equivalent for "failed"), and to manually maintain a 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've also usually had to overrid the didFail method - Apple incorrectly uses this to report that e.g. the YouTube player has taken over the handling of a YouTube video. It's NOT a fail, it's a "page was loaded by a different application".
e.g.
- (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
}
}
(If it is the same domain) you can call a function (in the parent) from the iframe.
top.iFrameLoaded();
To tell if a webview is loading, you can use
webView.isLoading
to check if all the frames of a webview are done loading. No counting the number of iframes necessary. Simply check if isLoading
is true inside webViewDidFinishLoad:
http://developer.apple./library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html
本文标签: javascriptHow to determine iFrame finished loading in UIWebViewStack Overflow
版权声明:本文标题:javascript - How to determine iFrame finished loading in UIWebView - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741614968a2388473.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论