
Với thủ thuật blog này, khi người dùng vào website, nếu họ không biết xem nội dung gì...thì nút này rất có ích với họ. Nó giống như trò chơi xổ số vậy! Rất thú vị và tăng tính tương tác cho người dùng.
Để thực hiện thủ thuật này Nút bài viết ngẫu nhiên/Random Post cho Blogspot, các bạn chỉ cần làm theo các bước sau đây.
Chèn đoạn mã code sau vào HTML của website hoặc một Widget HTML/Javascript
Đầu tiên các bạn vào Blog Title → Layout → Add Widget → HTML/JavaScript. Và copy đoạn mã code sau đây vào và Save As hay Lưu lại nhé!
<style scoped="" type="text/css">#st-random a{display:block;text-align:center;border:1px solid #202020;line-height:50px;font-size:150%;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;text-decoration:none;background-color:#2e2e2e;color:#FFF;-moz-box-shadow:0 1px 2px #000,inset 0 1px 100px #202020;-webkit-box-shadow:0 1px 2px #000,inset 0 1px 100px #202020;box-shadow:0 1px 2px #000,inset 0 1px 100px #202020}#st-random a:hover{background-color:#007abe}</style> <div id="st-random"></div> <script type="text/javascript">/*<![CDATA[*/function showLucky(k){var h=k.feed;var g=h.entry||[];var i=h.entry[0];for(var j=0;j<i.link.length;++j){if(i.link[j].rel=="alternate"){window.location=i.link[j].href}}}function fetchLuck(c){script=document.createElement("script");script.src="/feeds/posts/summary?start-index="+c+"&max-results=1&alt=json-in-script&callback=showLucky";script.type="text/javascript";document.getElementsByTagName("head")[0].appendChild(script)}function feelingLucky(i){var g=i.feed;var h=parseInt(g.openSearch$totalResults.$t,10);var f=Math.floor(Math.random()*h);f++;a=document.createElement("a");a.href="#random";a.rel=f;a.onclick=function(){fetchLuck(this.rel)};a.innerHTML="Bài ngẫu nhiên";document.getElementById("st-random").appendChild(a)};/*]]>*/</script> <script src="/feeds/posts/summary?max-results=0&alt=json-in-script&callback=feelingLucky"></script>
Ok, vậy là đã xong. Chúc các bạn thành công nhé!