How to tell the difference between an iframe loading vs. entire page loading in a UIWebView?

后端 未结 3 797
暖寄归人
暖寄归人 2021-02-04 09:18

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?

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-04 10:01

    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;
    

提交回复
热议问题