The textbox adds “http://” to what ever the users enters (Ex. “google.com” turns to “http://google.com”) before sending to the web browser, but if the user enters “http://” before their website you get an error.
this is my code:
private void bargo_Click(object sender, RoutedEventArgs e)
{
Uri targetUri = new Uri(System.String.Format("http://{0}", bar.Text));
web.Navigate(targetUri);
}
You can test whether bar.text already starts with http:// like this:
If your user enters “https://” or “ftp://” (or gopher://, irc://, ircs://, ftp://, news://, nntp://, worldwind://, telnet://, svn://, git://, mms:// and mailto:) this method will still add “http://” and fail.
A better solution would be to pass a string into web.Navigate() instead of a uri. When you pass in a string, the WebBrowser control automatically adds http:// like a browser would.
EDIT: For Windows Phone 7