Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebBrowser Control Check Domain

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?

like image 330
JacobTheDev Avatar asked Feb 12 '26 09:02

JacobTheDev


1 Answers

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

like image 56
johnhforrest Avatar answered Feb 14 '26 00:02

johnhforrest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!