* Login ke Blogger.com
* Kemudian Tata Letak
* Pilih Edit HTML
* Centang Expand Widget
* Copas kode berikut dibawah kode "</head>"
Lalu copy script berikut diatasnya
<script type="text/javascript">
//<![CDATA[
var _yourBlogUrl = "http://infoduniaterbaru.blogspot.com";
function randomPost() {
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
var theUrl = _yourBlogUrl +"/feeds/posts/summary?alt=json-in-script&callback=getTotalPostsCallback&start-index=1&max-results=1";
script.setAttribute("src", theUrl);
document.documentElement.firstChild.appendChild(script);
};
function getTotalPostsCallback(json) {
var totalResults = json.feed.openSearch$totalResults.$t;
if (totalResults > 0) {
getRandomPostNumber(totalResults);
}
};
function getRandomPostNumber(totalResults) {
var randomNumber = Math.floor((Math.random() * totalResults) + 1);
getRandomUrl(randomNumber);
};
function getRandomUrl(randomNumber) {
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
var theUrl = _yourBlogUrl +"/feeds/posts/summary?alt=json-in-script&callback=getTheUrlCallback&start-index=" + randomNumber + "&max-results=1";
script.setAttribute("src", theUrl);
document.documentElement.firstChild.appendChild(script);
};
function getTheUrlCallback(json) {
var theUrl = json.feed.entry[0].link[0].href;
window.location.href = theUrl;
}
//]]>
</script>
Ganti teks warna ungu dengan alamat blog kalian.
Save Template
Kemudian Tambahkan sebuah Element halaman -> HTML/Javascript
copas script dibawah
<a href="javascript:randomPost();">View Random Post</a>
Save Template
0 Response to "Cara Membuat Random Post"
Post a Comment