UIWebView: when did a page really finish loading?

后端 未结 11 1230
轮回少年
轮回少年 2020-11-29 00:09

I need to know, when a web page has completely been loaded by UIWebView. I mean, really completely, when all redirects are done and dynamically loaded content is ready. I tr

11条回答
  •  无人及你
    2020-11-29 00:38

    Make your View Controller a delegate of the UIWebView. (You can either do this in Interface Builder, or by using this code in the viewDidLoad method:

    [self.myWebView setDelegate:self];
    

    Then use the method described in the accepted answer here: webViewDidFinishLoad: Firing too soon?.

    The code:

    -(void) webViewDidFinishLoad:(UIWebView *)webView
    {
        NSString *javaScript = @"function myFunction(){return 1+1;}";
        [webView stringByEvaluatingJavaScriptFromString:javaScript];
    
        //Has fully loaded, do whatever you want here
    }
    

提交回复
热议问题