Random Posts Widget Blogger

Seen a lot people finding a Random Post widget for there blog? Then thought should have an tutorial on how to install it too in the blog.Well, here it is. If you want to know what it do is, whenever a reader click on link created by this widget all the times a different post will open for the reader in the blog as by luck.

Now lets see how to install it in your blog as it is very simple.

Go to Page Elements and click on Add a Gadget on the sidebar. Select HTML/Javascript and add the javascript code given below and save the widget/gadget.

<div id=”myLuckyPost”></div> <script type=”text/javascript”> function showLucky(root){ var feed = root.feed; var entries = feed.entry || []; var entry = feed.entry[0]; for (var j = 0; j < entry.link.length; ++j){if (entry.link[j].rel == ‘alternate’){window.location = entry.link[j].href;}}} function fetchLuck(luck){ script = document.createElement(‘script’); script.src = ‘/feeds/posts/summary?start-index=’+luck+’&max-results=1&alt=json-in-script&callback=showLucky’; script.type = ‘text/javascript’; document.getElementsByTagName(‘head’)[0].appendChild(script); } function feelingLucky(root){ var feed = root.feed; var total = parseInt(feed.openSearch$totalResults.$t,10); var luckyNumber = Math.floor(Math.random()*total);luckyNumber++; a = document.createElement(‘a’); a.href = ‘#random’; a.rel = luckyNumber; a.onclick = function(){fetchLuck(this.rel);}; a.innerHTML = ‘Are ya feeling lucky, punk?’; document.getElementById(‘myLuckyPost’).appendChild(a); } </script> <script src=”/feeds/posts/summary?max-results=0&alt=json-in-script&callback=feelingLucky”></script><noscript><a href="http://anshuldudeja.blogspot.com" target="_blank">Blogger Hacks</a></noscript>

I hope you will install it very easily Good Luck!!


  1. lvs January 30, 2009
  2. Anonymous April 11, 2009
  3. wazzupweb May 21, 2009
  4. wazzupweb May 21, 2009
  5. The Blind Assassin October 25, 2009
  6. Nathawud November 26, 2009
  7. Misha Vaisburg July 10, 2010

Leave a Reply