# Loading a Random HTML Page Inline

**URL:** <https://forum.kirupa.com/t/loading-a-random-html-page-inline/326996>\
**Category:** web dev\
**Created:** [January 29, 2012, 10:40pm UTC](https://forum.kirupa.com/t/loading-a-random-html-page-inline/326996 "2012-01-29T22:40:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![damonpla](https://avatars.discourse-cdn.com/v4/letter/d/ecae2f/32.png) [@damonpla](https://forum.kirupa.com/u/damonpla)\
**Post date:** [January 29, 2012, 10:40pm UTC](https://forum.kirupa.com/t/loading-a-random-html-page-inline/326996/1 "2012-01-29T22:40:42Z")

</div>

First off, thank you for posting this tutorial on how to load random HTML pages into a div.

[http://www.kirupa.com/html5/loading\_random\_page\_inline\_pg1.htm](http://www.kirupa.com/html5/loading_random_page_inline_pg1.htm)

I got it to work if the pages I want to load are on the root, however I need to randomize 150 pages, so I would like to shove them into a folder for a cleaner server.

Here is the code which tells which pages to grab:

function loadExternalHTMLPage() {  
var xmlhttp;  
**var pagesToDisplay = [‘sample1.htm’, ‘sample2.htm’];**  
if (window.XMLHttpRequest) {  
xmlhttp = new XMLHttpRequest();  
} else {  
xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);  
}  
xmlhttp.onreadystatechange = function () {  
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {  
document.getElementById(“featuredArtist”).innerHTML = xmlhttp.responseText;  
}  
}  
var randomnumber = Math.floor(Math.random() \* pagesToDisplay.length);  
xmlhttp.open(“GET”, pagesToDisplay[randomnumber], true);  
xmlhttp.send();  
}

Since I will be using 150 different pages, I want these pages in a directory named “featured”, but the sample pages won’t show as soon as I enter a directory (shown below). Is this not the way to approach this in javascript?

**var pagesToDisplay = [’…/featured/sample1.htm’, ‘…/featured/sample2.htm’];**

I have tried these formats:

**’featured/sample1.htm’** & **'/featured/sample1.htm**

I have even tried placing the **‘inline.js’** into the featured folder but it stills calls the pages from the root not **/featured**.

Any help would be much appreciated!

Thanks!  
Damon
