zohar zohar - 2 months ago 15
iOS Question

How to close page in UIWebView and go back to app

In my app by pressing a button I want to open

UIWebView
on full screen, the
UIWebView
will load a HTML page that will hold a button that will close the
UIWebView
and return to app.

The problem is that I fail to make the button close the page and return to app.
I tried
parent.history.back()
and
history.back
and several versions of
self.close()
but nothing seems to work (BTW it work in browser but not from
UIWebView
.

any idea?
thanks
-Z

Answer
[UIWebViewDelegate][1] has your answer

    - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request            
                                    navigationType:(UIWebViewNavigationType)navigationType {
        if (request.URL == "SOME URL TO CLOSE WINDOW") {
            //do close window magic here!!
            [self stopLoading];
            return NO;
        }
        return YES;
    }
-(void)stopLoading{
    [_webView removeFromSuperview];
}

  [1]: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebViewDelegate_Protocol/Reference/Reference.html