Click to See Complete Forum and Search --> : Help with resolution code


alekskayy
10-05-2005, 05:18 AM
ok i want to make a code for a website so when the background loads in the page it will have support for all the different resolutions on a page... i have come up with:

<script language="javascript">
function getresimage()
{
switch(screen.width)
{
case 800: return "filename1.gif"
case 1024: return "filename2.gif"
case 2048: return "filename3.gif"
}
}
</script>

this just calls on the file but how would i make it display on the page? thankz in advance bye

konithomimo
10-05-2005, 05:48 AM
What you do is in the background part of the body call your function that returns your background image name. For example:

<body background="getresimage()">

That will make the background display the filename returned by getresimage.

Make sure that you use the proper folder paths though. If the image files are not in the same folder as the page calling them then the images wont display.

alekskayy
10-05-2005, 07:12 AM
ok i tried adding the function to the body tag as you said and the images are in the same directory but it still isnt displaying...n e ideas?

Vladdy
10-05-2005, 07:33 AM
What you do is in the background part of the body call your function that returns your background image name. For example:

<body background="getresimage()">

That will make the background display the filename returned by getresimage.

Make sure that you use the proper folder paths though. If the image files are not in the same folder as the page calling them then the images wont display.
Why bother replying when you have no clue what you are talking about:
1. background attribute has been depricated in favor of CSS declarations
2. <element attribute="scriptFunction()"> only works for attributes that define event handlers

To OP: Resolution has nothing to do with the size of the browser window one uses. If that background image is so important to your presentation use the one that looks reasonable with !800 px wide browser window and provide user alternative stylesheets first, and a way to switch between different background images using scripting second

alekskayy
10-05-2005, 08:26 AM
ok thanks evry1 for ur help but i got the solution:

<script>
if (screen.width <= 800)
{document.write("<body background=filename2.gif>")}

if (screen.width == 1024)
{document.write("<body background=filename3.gif>")}

if (screen.width >= 1280)
{document.write("<body background=filename3.gif>")}
</script>

take care evry1

Vladdy
10-05-2005, 10:53 AM
No you did not:
If scripting is disabled you end up with a malformed document

felgall
10-05-2005, 02:49 PM
Also you are testing the screen size and not the available area within the browser window. Someone may have a 1600x1200 screen and have their browser window set to 600x400. They would then only see part of the huge version of your background.

Also, the background should be defined in a stylesheet. The correct way to definer the body tag with all allowable attributes is <body>.

alekskayy
10-06-2005, 04:43 AM
its ok im not looking to please everyone lol..