Tuesday, October 28, 2008

Getting URL from UIWebView

It thought I'd post how to get the current URL string from a UIWebView object. Here you go:


NSString *currentURL
= myWebView.request.URL.absoluteString;


That is assuming myWebView is your UIWebView object.

To open a web page in Safari from a UIWebView, do this:


[[UIApplication sharedApplication]
openURL:myWebView.request.URL];


2 comments:

Brent Clay said...

Thanks for the tip!

Jeff Geerling said...

Awesome, and very elegant. Was trying to implement a JS-based method/assignment, but this one-liner fixed all my problems, and required a lot less code.