I use the WebBrowser-Control in my WPF-Application like
Now, when I navigat
Web browser control by default does not open default browser while a link is clicked and it opens the link clicked inside the browser in internet explorer only. Now wecan use _DocumentCompleted event but it needs an event based trigger, like link button, to work. Now the issue is if html in the browser control has href then this even will not work. Solution to this is using _NewWindow event. Code is given below
/* The event handler*/
private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
{
var webbrowser = (WebBrowser)sender;
e.Cancel = true;
OpenWebsite(webbrowser.StatusText.ToString());
webbrowser = null;
}
/* The function call*/
public static void OpenWebsite(string url)
{
Process.Start(GetDefaultBrowserPath(), url);
}
private static string GetDefaultBrowserPath()
{
string key = @"http\shell\open\command";
RegistryKey registryKey =
Registry.ClassesRoot.OpenSubKey(key, false);
return ((string)registryKey.GetValue(null, null)).Split('"')[1];
}
Suggestions for improvement are invited. Happy coding.