Re: JavaScript: Different backgrounds

by 2Nerotik <2nerotik(at)nisa.net>

 Date:  Thu, 03 Feb 2000 23:28:18 -0800
 To:  "RBaggs" <rbaggs(at)ij.net>,
hwg-techniques(at)hwg.org
 In-Reply-To: 
  todo: View Thread, Original
Did it, took a bit of guess work because the script did not like being = 
800 then a friend who
just finished a C++ course said to try a double equals sign and viola it 
worked.

Here is the final script I came up with that works, not tested in NN just 
in IE but it 'should'
work in both without a problem with the exception of the 
BGPROPERTIES="Fixed" attribute
since NN can't fix a wallpaper in place.

If someone can come up with cleaner code then by all means.

< SCRIPT Language="JavaScript1.2">
<!--

function getWallpaper() {
if (screen.Width == 1024) {
         i = 0 }
if (screen.Width ==  800)  {
         i = 1 }
if (screen.Width == 640)  {
         i = 2 }

image = new Array(3);
image[0]  = "1024.jpg";
image[1]  = "800.jpg";
image[2]  = "640.jpg";

document.write('<BODY BACKGROUND="' + image[i] + '" BGPROPERTIES="Fixed">');

   }
//** end hiding of JavaScript -->
< /SCRIPT>

This part goes wherever you want the image to be:
<SCRIPT>  getWallpaper(); </SCRIPT>

Alternate to the BODY tag use the following style instead:
document.write('<STYLE> body { background: url(' + image[i] + '} </STYLE>');

Both tested and work perfectly.

At 09:59 PM 01/02/2000 -0500, RBaggs wrote:
>I have tried to set up a script that will load the appropriate sized 
>background of different images as a background dependent upon the screen 
>setting size. Hint on how this would be set up?
>Roland Baggs

.oOo.
|| Some mistakes are too much fun to only make once.
||
||  Addicted 2 Swing ---> http://www.nisa.net/~2nerotik/
||  Fontaholic ? ---> http://www.fontsanon.com
||  HTML Writers Guild ---> http://www.hwg.org

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA