Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
Blogger Json undefined url when items less than 5

I'm trying to fix this code

var homePage = "https://blogger.googleblog.com/",
    maxResaults = 4;

function randomPosts(a) {
    if (document.getElementById("random-posts")) {
        var e = shuffleArray(a.feed.entry),
            title, link, img, content = "",
            ct = document.getElementById("random-posts");
        for (var i = 0; i < maxResaults; i++) {
            for (var j = 0; j < maxResaults; j++) {
                if (e[i].link[j].rel == "alternate") {
                    link = e[i].link[j].href;
                    break
                }
            }
            var title = e[i].title.$t;
            content += '<li class="random-posts"><a href="' + link + '" title="' + title + '" target="_blank">' + title + '</a></li>'
        }
        ct.innerHTML = content
    }
}

function shuffleArray(arr) {
    var i = arr.length,
        j, temp;
    if (i === 0) return false;
    while (--i) {
        j = Math.floor(Math.random() * (i + 1));
        temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp
    }
    return arr
}
var random_post = document.createElement('script');
random_post.src = homePage + '/feeds/posts/default?alt=json-in-script&orderby=published&max-results=999&callback=randomPosts';
document.getElementsByTagName('head')[0].appendChild(random_post);
<ul id="random-posts"></ul>

when I make maxResaults less than 5 it shows an error with the items url it become undefined more than 5 work fine can anyone point to the problem ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!