Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1019023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:56:47+00:00 2026-05-16T10:56:47+00:00

I’ve looked for some help on the reddit site itself, but I still can’t

  • 0

I’ve looked for some help on the reddit site itself, but I still can’t quite figure it out, so I’ve reposted here. I’ve also searched this forum but I haven’t found a close enough answer and don’t know enough about programming to extrapolate from what I have found.

I’m certainly not much of a programmer; this seems possible but I can’t work out how to do it.

I’d like to be able to insert a link to a reddit thread on a webpage and also display the number of comments in the thread I’ve linked to.

I understand how to do the first part:

<a href="http://www.reddit.com/r/redditdev/comments/d570p/reddit_widget_help/" 
target="_blank">4eddit thread<br /></a>

And I know I can get info on the thread by appending .josn to the url

http://www.reddit.com/r/redditdev/comments/d570p/reddit_widget_help.json

And I know the data I need in the json output is “num-comments“.

How can I come up with something that looks like this…

reddit widget help (n comments)

…where n is pulled from the .json info and is updated when the page is loaded?

Update

I’ve used Matthew Flaschen’s example below to get it working.

In the last hour or so I’ve discovered that moodle (our online course management system) doesn’t support JQuery but only YUI. And in any event I can’t seem to get and YUI javascript examples to run in the html sections that I am able to edit (I assume this is because I’m unable to edit the section).

As a workaround I can load this html:

<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function show_num_comments(response) {
            $(function() {
                $('#comm_count').text(response[0].data.children[0].data.num_comments);
            });
        }
    </script>
    <script type="text/javascript" src="http://www.reddit.com/r/redditdev/comments/d570p/.json?jsonp=show_num_comments"></script>
</head>
<body>  
    <div id="thread"><span id="comm_count"></span> comments</div>
</body>

in an iframe. Unfortunately it means I’ll have to have a separate html file (for each iframe) for each lesson/comment thread I’d like students to discuss.

Any idea for making this a bit more elegant?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:56:48+00:00Added an answer on May 16, 2026 at 10:56 am

    I made a simple proof-of-concept. You can test it on JSFiddle. (with jQuery) (without jQuery):

    Thread has <span id="comm_count"></span> comments
    <script type="text/javascript">
        function show_num_comments(response)
        {
           window.addEventListener("load", function()
           {
             document.getElementById('comm_count').textContent = response[0].data.children[0].data.num_comments;
           }, false);
        }
    </script>
    <script type="text/javascript" src="http://www.reddit.com/r/redditdev/comments/d570p/reddit_widget_help/.json?jsonp=show_num_comments"></script>
    

    Because this is cross-domain, we have to use JSONP (JSON with padding). Basically, this means we provide a special function on our page (show_num_contents), then use a script tag. Reddit responds with a a script that calls the function, passing in the JavaScript object.

    We use addEventListener to wait until load to manipulate the DOM.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.