Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Created April 16, 2017 11:41
Embed
What would you like to do?
Codebehind for the mainpage of my application
private void WebView_OnNavigating (object sender, WebNavigatingEventArgs e)
{
var url = e.Url.ToLowerInvariant ();
if (url.Contains ("thirdparty.com") || url.Contains ("vimeo.com") || url.Contains ("bid.g.doubleclick.net")) {
// Do nothing, links are loaded as embedded
} else if (url.StartsWith ("https://getmypdfurl.com", StringComparison.Ordinal)) {
e.Cancel = true;
if (Device.OS == TargetPlatform.Windows)
Device.OpenUri (new Uri (e.Url));
else
Navigation.PushAsync (new ShowPdfPage (e.Url));
} else if (!url.StartsWith ("https://ourwebapplication.com", StringComparison.Ordinal)) {
e.Cancel = true;
if (Device.OS == TargetPlatform.iOS) {
try {
DependencyService.Get<IWebBrowserService> ().OpenUrl (e.Url);
} catch {
Device.OpenUri (new Uri (WebUtility.UrlDecode (e.Url)));
}
return;
}
Device.OpenUri (new Uri (WebUtility.UrlDecode (e.Url)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment