Results 1 to 7 of 7

Thread: Random Background

  1. #1
    Join Date
    Mar 2006
    Location
    Australia
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Random Background

    Hi,
    I was just wondering if anybody knew how the backgrounds on Popstar Madonna's site keeps changing? Is it a Javascript or something else? I just have to know!
    Thankyou to anyone that can help me!

    P.S. The site is http://madonna.com/ and is best viewed in Internet Explorer or Mozilla Firefox!

  2. #2
    Join Date
    Mar 2006
    Location
    Somewhere....
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking Hello....

    Here, this should help:

    place this in the <head> section of your page:

    HTML Code:
    <script language="javascript"> 
    <!-- 
    bg = new Array() 
    bg[0] = ("firstimage.gif") 
    bg[1] = ("secondimage.jpg") 
    bg[2] = ("third.gif") 
    bg[3] = ("fourth.gif")
    bg[4] = ("fifth.gif") 
    bg[5] = ("sixth.gif") 
    bg[6] = ("seventh.jpg")
    bg[7] = ("eighth.gif")  
    var Numb = Math.round(7 * Math.random()); 
    var back = bg[Numb] 
    document.write("<body bgcolor='#000000' text='#ffd700'link='#ffa500' vlink='#cc0000' alink='#ffa500' background=" +back+ ">")
     --> </script>
    Just replace those above images with those from you directory..

    bye.

  3. #3
    Join Date
    Mar 2006
    Location
    Australia
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    OMG, Thankyou sooooo much I appreciate this heaps... I couldn't find this anywhere! The closest thing was a random color changer!
    Thank You!!

  4. #4
    Join Date
    Mar 2006
    Location
    Somewhere....
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking O.k

    It was a pleasure doing Buisness!

    Glad I could help

    Bye.

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Hmm.... you'd need to remember to not include an extra <body>, right?
    And wouldn't you want the script below the </head> tag so it replaces the body tag at the right point?

  6. #6
    Join Date
    Mar 2006
    Location
    Somewhere....
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Hmm.

    Hi there...\

    Originally posted by djr33
    Hmm.... you'd need to remember to not include an extra <body>, right?
    And wouldn't you want the script below the </head> tag so it replaces the
    body tag at the right point?

    No. You would lay out your page, just like you would if you were making a
    site. And that means you include the <body> tag. Because without this
    <tag> the web site won't function.


    Another: you add the code to the <head> section of you source, just dont
    specify any value for a bgcolor, or background in the original <body> attribute.

    All this code does, is overide the body's bgcolor function, if you don't put
    one, and display the images out in the array, on random turns. Simple.

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Actually, djr33 is right. Using this script with a normally-laid-out site, you're going to end up with something that looks like this (after the script has run):
    Code:
    <head>
      <body bgcolor='#000000' text='#ffd700'link='#ffa500' vlink='#cc0000' alink='#ffa500' background='seventh.gif'>
    </head>
    <body>
      ... rest of page ...
    This is not well-formed HTML. One solution would be, as djr33 suggested, to put the script in the place of the <body> tag. However, this will destroy the page in non-JS browsers. The correct way to do this would be:
    Code:
    <head>
      <title></title>
      <script type="text/javascript">
        onload = function() {
          bg = new Array("firstimage.gif", "secondimage.jpg", "thirdimage.png", "fourthimage.tif"/*, ... */);
          var Numb = Math.floor(bg.length * Math.random());
          document.body.style.backgroundImage="url(" + bg[Numb] + ")";
        };
      </script>
    </head>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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