我正在開發一個網頁,但我需要一個JS腳本從目錄中選擇一個隨機頁面。目前我有這個劇本;JavaScript - 從目錄中選擇一個隨機頁面
<!-- Hide this script from old browsers --
var links = new Array(10)
links[0] = "anal.html"
links[1] = "brr-fail.htm"
links[2] = "anal.html"
links[3] = "brr-fail.htm"
links[4] = "anal.html"
links[5] = "brr-fail.htm"
links[6] = "anal.html"
links[7] = "brr-fail.htm"
links[8] = "anal.html"
links[9] = "brr-fail.htm"
links[10] = "anal.html"
function go() {
var a = 1+Math.round(Math.random()*10)
var i = a
location = links[i]
}
// -- End Hiding Here -->
</script>
(別擔心,它不是同性戀色情 - 米姆)
正如你所看到的,它是有點複雜的,有時它帶來了一個「未定義」頁面錯誤。有什麼辦法讓它從整個目錄中選擇一個隨機頁面?說一些像;
www.urlhere.co.uk/memes/random/
謝謝你們
JS是客戶端,你不能用它列出服務器上的目錄。 – F0G