On Windows Phone, how can I check what domain someone has clicked on, and if it's not a certain domain, open IE instead?
Basically, if the user is on http://m.google.com/app/plus or any sub page, stay in the webbrowser control, but if it's something off site, preferably even if it's still on http://m.google.com, open in Internet Explorer.
I'm writing in C#, and please be specific, I'm insanely new to this.
EDIT: Also, is there a way to add a load bar to the WebBrowser control?
Assuming your WebBrowser XAML looks something like this:
<phone:WebBrowser Name="browser_Post" Navigating="OnBrowserPostNavigating">
Your event handler would look like this:
private void OnBrowserPostNavigating(object sender, NavigatingEventArgs e)
{
// meaning the link is external, we want to open this outside of our app
if (!e.Uri.AbsoluteUri.Contains("m.google.com/app/plus"))
{
e.Cancel = true;
WebBrowserTask task = new WebBrowserTask();
task.URL = e.Uri.AbsoluteUri;
task.Show();
}
}
e.Uri.AbsoluteUri will be the absolute URI of the link being clicked, i.e., http://www.google.com. The String.Contains() is a simplistic way of checking the user's domain, but it should be sufficient.
The WebBrowserTask will open IE using the external URL, and all other links that are local to Google+ will stay within your local WebBrowser.
Edit
There is actually almost an identical question here:
want to open Link in external browser of WP7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With