Click to See Complete Forum and Search --> : Problem with my script


rsines
12-23-2002, 05:42 PM
I am trying to write a script to resize images according to the viewers screen resolution. Can anyone tell me whats wrong with this script?

<SCRIPT LANGUAGE="JavaScript1.2">

if (screen.height>=960 & screen.width>=1280)
{document.write("<img src='background.jpg' width=1250 height=731>");}
{document.write("<img src='title.gif' width=180 height=44>");}
{document.write("<img src='rose.gif' width=93 height=133>");}
{document.write("<img src='divider.gif' width=514 height=51>");}

else
if (screen.height=864 & screen.width=1152)
{document.write("<img src='background.jpg' width=1125 height=658>");}
{document.write("<img src='title.gif' width=162 height=39>");}
{document.write("<img src='rose.gif' width=83 height=119>");}
{document.write("<img src='divider.gif' width=462 height=46>");}

else
if (screen.height=768 & screen.width=1024)
{document.write("<img src='background.jpg' width=1000 height=585>");}
{document.write("<img src='title.gif' width=144 height=35>");}
{document.write("<img src='rose.gif' width=74 height=106>");}
{document.write("<img src='divider.gif' width=411 height=41>");}

else
if (screen.height=720 & screen.width=960)}
{document.write("<img src='background.jpg' width=938] height=548>");}
{document.write("<img src='title.gif' width=135 height=33>");}
{document.write("<img src='rose.gif' width=69 height=99>");}
{document.write("<img src='divider.gif' width=385 height=38>");}

else {document.write("<img src='background.jpg' width=781 height=457>"); }
{document.write("<img src='title.gif' width=113 height=27>"); }
{document.write("<img src='rose.gif' width=58 height=83>"); }
{document.write("<img src='divider.gif' width=321 height=32>"); }

</script>

swon
12-23-2002, 05:46 PM
Use screen.availWidth and screen.availHeight instead of screen.width or screen.height.

rsines
12-23-2002, 06:09 PM
I still get an error with this code, the error is in the first esle statement

<SCRIPT LANGUAGE="JavaScript1.2">

if (screen.availHeight>=960 & screen.availWidth>=1280)
{document.write("<img src='background.jpg' width=1250 height=731>");}
{document.write("<img src='title.gif' width=180 height=44>");}
{document.write("<img src='rose.gif' width=93 height=133>");}
{document.write("<img src='divider.gif' width=514 height=51>");}

else
if (screen.availHeight=864 & screen.availWidth=1152)
{document.write("<img src='background.jpg' width=1125 height=658>");}
{document.write("<img src='title.gif' width=162 height=39>");}
{document.write("<img src='rose.gif' width=83 height=119>");}
{document.write("<img src='divider.gif' width=462 height=46>");}

else
if (screen.availHeight=768 & screen.availWidth=1024)
{document.write("<img src='background.jpg' width=1000 height=585>");}
{document.write("<img src='title.gif' width=144 height=35>");}
{document.write("<img src='rose.gif' width=74 height=106>");}
{document.write("<img src='divider.gif' width=411 height=41>");}

else
if (screen.availHeight=720 & screen.availWidth=960)}
{document.write("<img src='background.jpg' width=938] height=548>");}
{document.write("<img src='title.gif' width=135 height=33>");}
{document.write("<img src='rose.gif' width=69 height=99>");}
{document.write("<img src='divider.gif' width=385 height=38>");}

else {document.write("<img src='background.jpg' width=781 height=457>"); }
{document.write("<img src='title.gif' width=113 height=27>"); }
{document.write("<img src='rose.gif' width=58 height=83>"); }
{document.write("<img src='divider.gif' width=321 height=32>"); }

</script>

swon
12-23-2002, 06:13 PM
Uh, there's a few faults in the script, I try to make it work...

swon
12-23-2002, 06:23 PM
OK, I think that was it (don't forget to bring all the broken lines which made the forum to the same line):

<SCRIPT LANGUAGE="JavaScript1.2">
x = screen.availHeight;
y = screen.availWidth;
alert("Your Screen has " + y + "x" + x + "pixels");
if (screen.availHeight>=960 && screen.availWidth>=1280)
{
document.write("<img src='background.jpg' width=1250 height=731>");
document.write("<img src='title.gif' width=180 height=44>");
document.write("<img src='rose.gif' width=93 height=133>");
document.write("<img src='divider.gif' width=514 height=51>");
}

if (screen.availHeight == 864 && screen.availWidth == 1152)
{
document.write("<img src='background.jpg' width=1125 height=658>");
document.write("<img src='title.gif' width=162 height=39>");
document.write("<img src='rose.gif' width=83 height=119>");
document.write("<img src='divider.gif' width=462 height=46>");
}


if (screen.availHeight==768 && screen.availWidth==1024)
{
document.write("<img src='background.jpg' width=1000 height=585>");
document.write("<img src='title.gif' width=144 height=35>");
document.write("<img src='rose.gif' width=74 height=106>");
document.write("<img src='divider.gif' width=411 height=41>");
}


if (screen.availHeight==720 && screen.availWidth==960)
{
document.write("<img src='background.jpg' width=938] height=548>");
document.write("<img src='title.gif' width=135 height=33>");
document.write("<img src='rose.gif' width=69 height=99>");
document.write("<img src='divider.gif' width=385 height=38>");
}

else {
document.write("<img src='background.jpg' width=781 height=457>");
document.write("<img src='title.gif' width=113 height=27>");
document.write("<img src='rose.gif' width=58 height=83>");
document.write("<img src='divider.gif' width=321 height=32>");
}

</script>

swon
12-23-2002, 07:11 PM
Does it?