Skip to content

Instantly share code, notes, and snippets.

@ryanvalentin
Last active March 1, 2023 16:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanvalentin/6124471 to your computer and use it in GitHub Desktop.
Save ryanvalentin/6124471 to your computer and use it in GitHub Desktop.
Using Disqus in a WebBrowser control in Windows
// Url of Comments page
private string CommentsUri = "http://yoursite.com/comments/your_static_comments_page.html?"
+ "shortname=" + "YOUR_SHORTNAME"
+ "&url=" + HttpUtility.UrlEncode("ORIGINAL_ARTICLE_URL")
+ "&title=" + HttpUtility.UrlEncode("ORIGINAL_ARTICLE_TITLE")
+ "&identifier=" + HttpUtility.UrlEncode("ORIGINAL_ARTICLE_IDENTIFIER");
private void Browser_Loaded(object sender, RoutedEventArgs e)
{
Browser.IsScriptEnabled = true; // Make sure javascript is enabled
Browser.Navigate(new Uri(CommentsUri, UriKind.Absolute));
}
// Event that fires when the browser finishes loading a page
private void Browser_Navigated(object sender, NavigationEventArgs e)
{
// Get the current window's URL string
string navigatedUri = e.Uri.OriginalString.ToLowerInvariant();
// Array of URLs that indicate the user has just logged in
string[] patterns = { "disqus.com/next/login-success", "disqus.com/_ax/google/complete", "disqus.com/_ax/twitter/complete", "disqus.com/_ax/facebook/complete" };
if (patterns.Any(navigatedUri.Contains))
{
// If there was a match, go back to the comment thread
Browser.Navigate(new Uri(CommentsUri, UriKind.Absolute));
}
}
@ryanvalentin
Copy link
Author

The "CommentsUri" should point to a hosted page on your site that uses this template: https://github.com/disqus/DISQUS-API-Recipes/blob/master/mobile/js/mobiletemplate.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment