Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4246862
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:01:53+00:00 2026-05-21T04:01:53+00:00

I need to be able to swap a background image on page refresh. I

  • 0

I need to be able to swap a background image on page refresh. I am attempting to do this with javascript and I’m referencing the id I have set for the body of the page. Here is what I have come up with so far and it doesn’t seem to be working:

<script type="text/javascript">
    window.onload = choosePic;

    function choosePic() {
    var myPix = new Array("/CoVPrototype/images/Homepage/skyline_bkgd_blue_fixed.jpg", "/CoVPrototype/images/AboutPage/about_bkgd.jpg", "/CoVPrototype/images/GovernmentPage/gov_bkgd.jpg", "/CoVPrototype/images/newsPage/news_bkgd.jpg", "/CoVPrototype/images/parkPage/park_bkgd.jpg", "/CoVPrototype/images/propertyPage/property_bkgd.jpg", "/CoVPrototype/images/enviroPage/enviro_bkgd.jpg", "/CoVPrototype/images/transportPage/transport_bkgd.jpg", "/CoVPrototype/images/businessPage/business_bkgd.jpg");
    var randomNum = Math.floor(Math.random() * myPix.length);
    document.getElementById("home_style").src = myPix[randomNum];
    }

The tag I’m referencing in the HTML is set like this (please note, all other HTML tags have been applied… just not shown here for the sake of brevity):

<body id="home_style">
</body> 

And finally, my CSS looks like this:

body {
        margin:0;
        padding:0;
        font-size:62.5%;
        font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
}
    body#home_style {
            background:no-repeat bottom left fixed;
            width:100%;
    }

Should this work? What am I doing wrong?! I hope someone can help!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T04:01:53+00:00Added an answer on May 21, 2026 at 4:01 am

    This should work:

    document.getElementById("home_style").style.backgroundImage = "url(" + myPix[randomNum] + ")";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string that looks like this: (12.0+10)*31 I need to be able
Hopefully this is simple enough. I need to be able to add elements to
I have some flexibility here so I'm looking for some advice before I lock
I need to be able to extract jar files on the command line. Piece
I need to be able to run all tests in the current directory by
I need to be able to process an input file where there are 3
I need to be able to access my database, which in it's own isn't
I need to be able to bring up a list of items from the
I need to be able to select the whole word of a TMemo if
For a complicated reason I need to be able to finish() my activities when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.