Find us on Google+ Add Random Post Link To Your Blogger - Invatac - Technology Blog

Pages - Menu

Thursday, 18 October 2012

Add Random Post Link To Your Blogger


Random Post Link In Blogger
Random Post Link In Blogger

In this post i will show you how to put a random luck post's link to your blogger blog. Anyone visiting your website will be curious to see which is their random post, they just want to click that link, that will be redirected to some other post on your website.


How to add Random Post Link ?



# Step 1 :



Sign In to your blogger.



# Step 2 :



Select "Layout ", Click on Page Elements --> Add Gadget --> 

"HTML/JavaScript" 



# Step 3 :



Copy and Paste the below code to the "HTML/JavaScript"


<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 = 'Check Your Luckiest Post!'; document.getElementById('myLuckyPost').appendChild(a); } </script> <script src="/feeds/posts/summary?max-results=0&alt=json-in-script&callback=feelingLucky"></script>


Hope you all liked this tutorial, if you have any doubts please comment below.

Rahul Babu RAbout Me
I am a computer student looking for make my own name in the field of technology. Please add my to your circles.




No comments:

Post a Comment