Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    47
    Thanks
    3
    Thanked 0 Times in 0 Posts

    random include file javascript

    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?

  • #2
    New Coder TripperTreats's Avatar
    Join Date
    Oct 2006
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
     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

    Code:
     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.
    Psychedelic digital art at www.trippertreats.com.

    "And in the end, the love you take
    is equal to the love you make
    ."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •