PDA

View Full Version : Change Background Image - based on Browser Size



lodgest
05-09-2005, 03:41 PM
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 ??

lodgest
05-09-2005, 07:45 PM
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>

lodgest
05-09-2005, 07:54 PM
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>