In the [webView:shouldStartLoadWithRequest:navigationType:] event, how can you tell the difference between an iframe that\'s loading content vs. the entire page loading content?
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
BOOL isFrame = ![[[request URL] absoluteString] isEqualToString:[[request mainDocumentURL] absoluteString]];
}
I just used this method:
Let the page load normally by returning YES in the [webView:shouldStartLoadWithRequest:navigationType:] event, and once it's done loading, see if the WebView's URL changed or not... if it did that means it was a page redirect if not it probably means it was an iframe that was loaded.
I've successfully used the HTTP "referer" (the actual header is misspelled) field to detect this. This should either be the URL of the main page (available from the webview) or something else -- probably a frame.
NSString *referer = [request.allHTTPHeaderFields objectForKey:@"Referer"];
NSString *currentPage = [webView.request.mainDocumentURL absoluteString];
BOOL isFrameLoad = [referer isEqualToString:currentPage] == NO;