www.webdeveloper.com
Results 1 to 2 of 2

Thread: Banner JavaScript Required

Hybrid View

  1. #1
    Join Date
    Dec 2002
    Posts
    159

    Question Banner JavaScript Required

    Hi all,

    I'm trying to find a JavaScript script that would allow me to place a specific header image on each page.

    For example, a banner showing tennis players on a page about tennis and a banner showing football players on a page about football.

    Thanks in advance for any assistance provided.

  2. #2
    Join Date
    Nov 2007
    Posts
    409
    Not sure why you want to use JavaScript... but it would go like this:

    1- let's presume your page has a default image already in place that is coded like this:
    Code:
    <img src="default.jpg" id="imgBanner" />
    2- to change this image to some other image, you do like this:
    Code:
    document.getElementById('imgBanner').src = 'tennis.jpg'
    All that is left is for you to figure out how to decide which image you want to use on the page... e.g.,

    Code:
    //add this to every page:
    setBannerImage('tennis');
    and have this function in your common functions
    Code:
    function setBannerImage(topic){
      if (topic){
        var newImage;
        switch(topic){
          case 'tennis':
            newImage = 'tennis.jpg';
            break;
          case 'football':
            newImage = 'football_banner.jpg';
            break;
          default:
            newImage = 'default.jpg';
        }
        document.getElementById('imgBanner').src = newImage;
      }
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles