Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    about how to detecting user screen size

    hello question how to write a script to determine the user screen size so my home page can dectect the user resolution size and display the correct resolution size web pages
    Cool

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not sure if I'm understanding you but try this:

    Code:
    <script>
    w=screen.width;
    h=screen.height;
    if (w==640&&h==480) {
    location.replace("640.htm");
    }else if (w==800&&h==600) {
    location.replace("800.htm");
    }else if (w==1024&&h==768) {
    location.replace("1024.htm");
    }else if (w==1152&&h==864) {
    location.replace("1152.htm");
    }else if (w==1280&&h==1024) {
    location.replace("1280.htm");
    }else{
    location.replace("unknown.htm");
    }
    </script>

  • #3
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, this may seem a bit complicated, but I wrote this script to give me alot of flexibility with little coding.

    Code:
    /*************************
    SCREEN RESOLUTION
    **************************/
    // DECLARE THE ARRAY
    var resolution = new Array();
    
    // GET W&H VALUES
    var wide=screen.width;
    var high=screen.height;
    
    // EXACT RESOLUTION SCRIPT
    function xRes()
    {
    	var wide=screen.width; // How wide is your screen? (Larger number than Height)
    	var high=screen.height; // How tall is your screen? (Smaller number than Width)
    	var display=wide+' x '+high;
    
    	return display;
    }
    
    // RESOLUTION IS EXACTLY THIS SIZE
    resolution.is640x480=(wide==640 && high==480) ? true:false;
    resolution.is800x600=(wide==800 && high==600) ? true:false;
    resolution.is832x624=(wide==832 && high==624) ? true:false;
    resolution.is1024x768=(wide==1024 && high==768) ? true:false;
    resolution.is1152x870=(wide==1152 && high==870) ? true:false;
    resolution.is1280x1024=(wide==1280 && high==1024) ? true:false;
    resolution.is1600x1200=(wide==1600 && high==1200) ? true:false;
    
    // RESOLUTION IS THIS SIZE OR BIGGER
    resolution.min640x480=(wide>=640 && high>=480) ? true:false;
    resolution.min800x600=(wide>=800 && high>=600) ? true:false;
    resolution.min832x624=(wide>=832 && high>=624) ? true:false;
    resolution.min1024x768=(wide>=1024 && high>=768) ? true:false;
    resolution.min1152x870=(wide>=1152 && high>=870) ? true:false;
    resolution.min1280x1024=(wide>=1280 && high>=1024) ? true:false;
    resolution.min1600x1200=(wide>=1600 && high>=1200) ? true:false;
    
    // THIS WILL RETURN THE USERS EXACT RESOLUTION
    resolution.size=xRes();
    You could use this stuff in the following manner:

    Code:
    if (resolution.is800x600) // If resolution is exactly 800x600
    {
    	location.href='800x600.htm';
    }
    else if (resolution.is1024x768) // If resolution is exactly 1024x768
    {
    	location.href='1024x768.htm';
    }
    else if (resolution.min1152x870) // If resolution is AT LEAST this size
    {
    	location.href='1152up.htm';
    }
    Or, you could use the last command...

    Code:
    document.write('Your screen resolution is '+resolution.size);
    Hope this helps!

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Hey,
    found this old post and trying this...
    PHP Code:
    <script
     
    w=screen.width;  
    h=screen.height;  
    if (
    w==640&&h==480) {  location.replace("http://tab-archive.com/newsitew/Beta3.php?instrument=guitar&size=450");  
    }else if (
    w==800&&h==600) {  location.replace("http://tab-archive.com/newsitew/Beta3.php?instrument=guitar&size=450");  
    }else if (
    w==1024&&h==768) {  location.replace("http://tab-archive.com/newsitew/Beta3.php?instrument=guitar&size=620"); 
     }else if (
    w==1152&&h==864) {  location.replace("http://tab-archive.com/newsitew/Beta3.php?instrument=guitar&size=800"); 
     }else if (
    w==1280&&h==1024) {  location.replace("http://tab-archive.com/newsitew/Beta3.php?instrument=guitar&size=850");} 
     
    </script> 
    but it doesnt seem to work, it just doesnt redirect anwhere, like its just ignoring it.

    Anyone have any ideas?
    cheers
    P
    Last edited by sir pannels; 09-27-2003 at 11:43 AM.

  • #5
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Either...

    screen.width and screen.height

    or

    Code:
    <script>
    
    function getwindowsize() {
    
     return (typeof window.innerWidth!= 'undefined') ? innerWidth :
            (typeof document.body.clientWidth != 'undefined') ? document.body.clientWidth :
            (typeof document.documentElement.offsetWidth != 'undefined') ? document.documentElement.offsetWidth : null;
    }
    
    </script>
    Gets the actual window size.
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    hey,
    cheers - taking another look. in the 12XX screen and 800Xxxx it works fine its just screen sizes about the 12 one :s

  • #7
    New Coder
    Join Date
    Jul 2003
    Location
    Houston, Texas
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried this and it worked for me.

    <?php

    $sript_err=str_repeat("&middot",7)." Scripting Error ".str_repeat("&middot",7);

    ?>
    <noscript>
    <html>
    <head><title>Index</title></head>
    <body background="blue_fade.jpg"><br><br><br><br><br><br>
    <center><font size="8" face="arial" color="red">
    <b><?php echo $script_err; ?></font><br><br><br>
    <center><font size="6" face="arial" color="cyan">
    <b>Your web browser does not have scripting enabled.<br>
    Scripting must be enabled in order to run this application.<br><br>
    Contact ITCS to have scripting enabled on your workstation
    </font>
    <bgsound src="notify.wav"></bgsound>

    </body>
    </html>
    </noscript>

    <html>
    <head><title>Index</title>

    <script language="javascript">
    function openSite(){
    var wide=screen.width;
    var high=screen.height;
    var where_to;

    switch(wide)
    {
    case 640:
    switch(high)
    {
    case 480:
    where_to='ps_page_one_640.php';
    }
    break;
    case 800:
    switch(high)
    {
    case 600:
    where_to='ps_page_one_800.php';
    }
    break;
    case 1024:
    switch(high)
    {
    case 768:
    where_to='ps_page_one_1024.php';
    }
    break;
    case 1152:
    switch(high)
    {
    case 864:
    where_to='ps_page_one_1152.php';
    }
    break;
    case 1280:
    switch(high)
    {
    case 1024:
    where_to='ps_page_one_1280.php';
    }
    break;
    default:
    where_to='ps_page_one_1024.php';
    }

    var mainwin = window.open(where_to,"mainwin", "");
    window.opener='England_swings';
    window.close();
    }
    </script>

    </head>

    <body onload="openSite()">

    </body>
    </html>
    Beyond a critical point within a finite space, freedom diminishes as numbers increase. ...The human question is not how many can possibly survive within the system, but what kind of existence is possible for those who do survive."

  • #8
    New Coder
    Join Date
    Sep 2003
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I made a flash movie 750 by 500 on 1024 by 768 screen resolution. I know it looks big on 800 by 600 resolution. If I use above script. Does my movie looks the same as it would appear on 1024 by 768 screen resolution?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •