drawnonward, would you mind updating your answer with reference to the answer and comments below.
–
Toby AllenMar 23 '11 at 22:08

How to go back to the application once the user closes the browser?
–
Jhonny EversonMay 28 '11 at 16:14

2

@ Jhonny Everson: You have no control over what happens after any external app (including Safari) is closed. If you want to get back to your app when the user is done browsing, don't open up Safari, just use the UIWwbView and a "Done"-button.
–
geonJul 8 '11 at 16:03

In the webview delegate (i.e. in the implementation part of the class that you declared as delegate to the webview you are opening) by setting the delegate property of your webview. Usually this is done by adding the line self.webview.delegate = self; in your UIViewController subclass' viewDidLoad method.
–
KPMOct 2 '12 at 22:01

The other answers have one problem: they rely on the action you do and not on the link itself to decide whether to load it in Safari or in webview.

Now sometimes this is exactly what you want, which is fine; but some other times, especially if you have anchor links in your page, you want really to open only external links in Safari, and not internal ones. In that case you should check the URL.host property of your request.

I use that piece of code to check whether I have a hostname in the URL that is being parsed, or if it is embedded html: