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? It seems like the both call this same event with the same arguments, the only difference being the URL that's going to be loaded, so there is no way to tell the difference between the two.
I've thought of a few ways to tell the difference though:
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.What's the best way to do this? Can you think of any ways I haven't thought of? Do iframes have a special event/property I could manipulate with JavaScript to help me out?
Thanks
Update: It's not as simple as just checking the navigationType. Although clicking a link to open up a new page will show up as navigationType = 0, a JavaScript redirect (changing window.location) will show up as navigationType = 5. An iframe load also shows up as navigationType = 5. So when navigationType = 5, you don't know if the entire page changed URLs via JavaScript or if it is simply an iframe loading on the same page.
(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.
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