Results 1 to 3 of 3

Thread: Change Background Image - based on Browser Size

  1. #1
    Join Date
    May 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Change Background Image - based on Browser Size

    I'm new to JavaScript, but am trying to create a page that will load a different background image depending on the size of the browser.

    I have found code that will allow me to insert a different image based on 800 1024 or whatever size, but can't get it to work with background images.
    Not sure if it's my total inability to code,or whether it's not possible to do.

    Any ideas please ??

  2. #2
    Join Date
    May 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I've managed to create my own answer !!
    I'm sure I tried this before I posted the Q - but it now works...

    <SCRIPT LANGUAGE="JavaScript1.2">


    <!-- Begin
    if (screen.height >= 768 && screen.width >= 1024) { document.write("<BODY BACKGROUND

    ='images/1024.jpg'>"); }
    else { if (screen.height == 600 && screen.width == 800) { document.write("<img

    src='images/800.jpg' >"); }
    else { document.write("<img src='images/1024.jpg'>");
    }
    }
    // End -->
    </script>

  3. #3
    Join Date
    May 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Oops - it should of course be :

    <SCRIPT LANGUAGE="JavaScript1.2">


    <!-- Begin
    if (screen.height >= 768 && screen.width >= 1024) { document.write("<BODY BACKGROUND = 'images/1024.jpg'>"); }
    else { if (screen.height == 600 && screen.width == 800) { document.write("<BODY BACKGROUND = 'images/800.jpg' >"); }
    else { document.write("<BODY BACKGROUND = 'images/1024.jpg'>");
    }
    }
    // End -->
    </script>

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
  •