登入你的 【Blogger】>【設計】>【網頁元素】>【新增小工具】> 選【HTML/JavaScript】
複製貼入以下語法,好了之後儲存,儲存後不會在頁面上顯示:
<script type='text/javascript'> //<![CDATA[ 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 readLucky(root){ var feed = root.feed; var total = parseInt(feed.openSearch$totalResults.$t,10); var luckyNumber = Math.floor(Math.random()*total); luckyNumber++; fetchLuck(luckyNumber); } function feelingLucky(){ var script = document.createElement('script'); script.type = 'text/javascript'; script.src = '/feeds/posts/summary?max-results=0&alt=json-in-script&callback=readLucky'; document.getElementsByTagName('head')[0].appendChild(script); } //]]> </script>
接下來就要放置會顯示的連結語法,如下,到修改範本內即可放在想要放的位置,以下【隨機文章】請自行適當修改:
<a title="Random Post" onclick="feelingLucky()" href="#random">隨機文章</a>
0 留言