View Full Version : random include file javascript

01-14-2007, 10:05 PM
I dont know if this exists or would have to be written, but how hard would it be to make a javascript that would randomly choose between 6 different include files, onload or refresh, and display just one of the include files. The reason I want to do this may sound goofy, but it's the best way I can think of to do what I'm trying to do..I'm making a website with a main graphic at the top, image rollovers with mouseover effects and then content. The content will stay the same on each page, but if the page is refreshed or revisited, I want the top graphic and rollovers and surrounding background images to change, so the whole page looks different, but has the same content. I was going to do this with one huge background image using CSS, but if I do that, I cant change the rollover buttons with a style switcher, so I just decided to make the 6 individual pages and use an include file script that would randomly choose one of the 6 pages..any ideas?

01-15-2007, 12:56 AM
If it's a css file or Javascript file you want to include? Supposing so, if the files are named file1, ..., file6, you could do:

var rand = Math.floor(Math.random()*6)+1;
document.write('<style type="text/css" media="screen">@import url("file'+rand+'.css");</style>');
If it's a Javascript document, this last line would be

document.write('<script type="text/javascript" src="file'+rand+'.js");</script>');I'm pretty sure this will work. Let me know how it turns out.