Link to home
Start Free TrialLog in
Avatar of Rad1
Rad1

asked on

JavaScript to detect and adjust Screen Size

Hi,

I have the below function to adjust the screen size in Windows 7.  Is there a better way of doing this with %.  If yes, how do I do it?

Thank you!!!

function myWindow() {
             if (screen.width == 800) {
                 var wdth = 800;
                 document.body.style.zoom = screen.width / 940;
             }
             else if (screen.width == 1024) {
                 var wdth = 1024; 
                 document.body.style.zoom = screen.width / 1204;
             }
             else if (screen.width == 1152) {
                 var wdth = 1152;
                 document.body.style.zoom = screen.width / 1351;
             }
             else if (screen.width == 1280) {
                 var wdth = 1280;
                 document.body.style.zoom = screen.width / 1400;
             }

             else if (screen.width == 1440) {
                 var wdth = 1440;
                 document.body.style.zoom = screen.width / 1710;
             }
             if (screen.width == 1600) {
                 var wdth = 1600;
                 document.body.style.zoom = screen.width / 1600;
             }
         }

Open in new window

Avatar of Roonaan
Roonaan
Flag of Netherlands image

If you are targeting newer browsers, than in this situation, maybe CSS3 Media Queries can help.

http://css-tricks.com/css-media-queries/

You could then set the CSS zoom style by using the right media selectors

<style type="text/css">
@media screen and (min-width: 800px) and (max-width: 1023px) {
   body { zoom: 0.851;}
}
@media screen and (min-width: 1024px) and (max-width: 1151px) {
   body { zoom: 1;}
}
</style>

Open in new window


As a sidenote, I am not sure why you really want to force users zoom ratio, but that could have a valid design choice.

Regards,

-r-
Avatar of Rad1
Rad1

ASKER

Okay great!!!

On the other hand, how can I make all my ASP.NET page position:relative; ????

Thank you!
ASKER CERTIFIED SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rad1

ASKER

Thank you for the great info!!!