Hello welcome to Guide Tricks today in this tutorial I am going to show you how to add “feeling lucky widget to blogger” this widget is very good to your blogger blog it helps to make your visitor active in your blog by displaying good formation which is posted already on your blog. How the widgets works is, when a visitor clicks on the image display on your sidebar or any location that is place in the blog “Are you feeling lucky” he will be automatically redirected to a random post in your blog without asking the user to choose which article did he want to read or asking for category. You can add this widget on your blog in few seconds even you don’t have knowledge of coding. The step Is just go to your blog “layout” page and add the code given below into a “HTML/JavaScript” box and press the save button.
<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 you feeling lucky?';
document.getElementById('myLuckyPost').appendChild(a);
}
</script>
<script src="/feeds/posts/summary?max-results=0&alt=json-in-script&callback=feelingLucky"></script>

0 comments: