Skip to content Skip to sidebar Skip to footer

Webviewdidfinishload Not Calling When Having Javascript Content In Webpage

I'm using UIWebView in a project. Sometimes it doesn't call the webViewDidFinishLoad method. Because the web page have some javascripts. The method - (BOOL) webView: (UIWebView *)

Solution 1:

webViewDidFinishLoad method gets called when the UIWebView has finished loading the url, in your case since you are calling a javascript, it doesn't load your content, it just calls a javascript function in your already loaded webview. But YES you can catch the javascript actions in the same method you stated as below

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{

    NSString *url = [[request URL] absoluteString];

    if(navigationType == UIWebViewNavigationTypeLinkClicked){

          if([url rangeOfString:@"SOMETHING"].length > 0 ){ 
             //if your action returns something appended in your url like the anchors work//DO YOUR STUFFS       
          }
    }

    returnTRUE;


}

Solution 2:

apparently, the webview in ios checks specifically for "iframe" tags in the html's dom and in case it finds, it creates events based on that tag as well. therefore, a simple however a patchy solution would be adding the following code in the part of the dom that is changing (for example, in the actual template of each section):

<iframe></iframe>

did the trick for me..

Post a Comment for "Webviewdidfinishload Not Calling When Having Javascript Content In Webpage"