Search code examples
iosios5uiwebviewuiwebviewdelegate

Loading a webivew inside a webview in iOS


I am facing an issue while loading a UIWebView.I have a webview(1st) where a url is loaded.when that page is loaded,I am creating a small view which has webview (2nd) on top of the first webview,which is loading a second url.Basically I am loading a webview inside a webview.On click of a url in the second webview,the resulting url has to open in safari,outside the app. IF i am not setting [webview setDelegate:self],then the page is loaded in the small webview as intended but on click,nothing is happening..

However if i set delegae of second UIWebView as self,the url which needs to be loaded in second UIWebView is getting loaded in first url.

Has anyone done this kind of webview loading earlier. Please help.your help is deeply appreciated

Thanks


Solution

  • In your current class, you should test wich UIWebView delegate is dealing with First set:

    webView.delegate = self;
    

    then in shouldStartLoadWithRequest:

    //UIWebView *smallWebView;
    //UIWebView *mainWebView;
    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
    {
         if(webView == smallWebView
         {
             //Load stuff on safari
         }
         else
         {
             //This means that link was pressed in the mainWebView
             //Depending on your logic, you will load the smallWebView 
         }
    }