Search code examples
iphonehtmlwebviewmodal-dialog

Change the html in my webView


I want to change the .html in my webView from my modalViewController, but not always the same, I mean, I want to know some function that can tell me wich .html is in the screen, so I can change it for the next one, like a modalView controller but with .html files. Can I do that?


Solution

  • You can use the webview delegates methods to accomplish that

    To know what html file is being called, use

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

    and to know which url is being called you could do something like

    -(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    
        NSString *url = [[request URL] absoluteString];
    
        NSLog(@"my url is %@", url);
    
        return YES;
    
    }