Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Created April 16, 2017 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfversluis/6ec06800ac1f6c86451a4cb12242575c to your computer and use it in GitHub Desktop.
Save jfversluis/6ec06800ac1f6c86451a4cb12242575c to your computer and use it in GitHub Desktop.
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