Random post Feeling Lucky Blogspot

·
At a previous post is Easy Make Random post Blogspot,I have explained how to show a few titles of articles in the widget, now I tell how to display a random posting by using botton Feeling Lucky like in Google

I`m feeling lucky or random post widget for blogger is very important in making the old posts alive and keep visitors more time on your blog (depending on your posts quality)

* Go to Layout -> Page Element
* Add Gadget -> HTML / JavaScript
* paste the following code

<div id="myLuckyPost" style="text-align:center"></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 = 'View Random Post'; document.getElementById('myLuckyPost').appendChild(a); } </script> <script src="/feeds/posts/summary?max-results=0&alt=json-in-script&callback=feelingLucky"></script><div style="text-align: center;"><a href="http://www.kriep2.co.cc/2009/08/random-post-feeling-lucky-blogspot.html" target="_blank"><span style="font-size:xx-small;">Get This Widget</span></a></div>


# The red sentence is the text which will appear change it as you can
# If you want it to appear as a button like in Google. Use this code

<div id="myLuckyPost" style="text-align:center"></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 = '<button type="button">I`m Feeling Lucky</button>'; document.getElementById('myLuckyPost').appendChild(a); } </script> <script src="/feeds/posts/summary?max-results=0&alt=json-in-script&callback=feelingLucky"></script><div style="text-align: center;"><a href="http://www.kriep2.co.cc/2009/08/random-post-feeling-lucky-blogspot.html" target="_blank"><span style="font-size:xx-small;">Get This Widget</span></a></div>


Save, and see this example :




Related Article for this post :

0 comments:

Post a Comment

Read other Post

Label Cloud

Guest Books

My Stats!

My Popularity (by popuri.us)
Check Page Rank