I have done some searching and from what I can tell screen size can only be determined by javascript....

What I am attempting to do is to determine a user's screen size and then make a decision on whether or not to fill a column with information (for users with larger than 800x600) to prevent scrolling for users with smaller screen sizes.

It would only involve a simple php if statement if I can only determine the screen width so php can make the descision.

I can't use java because php is executed before Java even thinks about executing.

Also I want to avoid any refreshing of the page.

Any ideas or other insights?

    yep, this is javascript thing...

    all i can suggest is do the test in a page before you get to the php page then do with it whatever you want

      8 months later

      As i am reading this thread i was thinking of a way:
      before you load the website, you run a javascript to fetch the screen width and size (screen.width & screen.height) and put em into a hidden form. Then you make javascript post the form which passes the variables trough $GET or $POST to your target page, which can be the access page of your website. There you can store them into the session. Alternatively you can fill in this form trough a link that says 'layout screen' .

      little code extract of a possible initial page:


      global $s_screen;
      if ($_POST['vwidth']&&$_POST['vheight'])
      {
      	$s_screen = array();
      	$s_screen['width'] = $_POST['vwidth'];
      	$s_screen['height'] = $_POST['vheight'];
      	session_register("s_screen",$s_screen);
      }
      
      if (!$_SESSION['s_screen'])
      {?>
        <div>
           Determing screen size<br>Please hang on</br>
           <div style="display:none;"><form name=screenform action="<? echo $_SERVER['SCRIPT_NAME'];?>" method="POST">
      			<input type=text name="vwidth">
      			<input type=text name="vheight">
      		</form></div>
        </div>
        <script language="JavaScript" type="text/JavaScript">
             document.screenform.elements[0].value=screen.width;
             document.screenform.elements[1].value=screen.height;
             document.screenform.submit();
        </script>
      <?}
      
      

      [/COLOR]

        My website has generally a lot to display. Css position is the solution in this case, but not without this checking of the screen size. I got a comment of a user that worked in a very high desktop resolution, that her screen looked so empty, and all the space was thrown away to spacing. My page consists of two main block elements that have to be displayed side by side, each having a minimum width to prevent them from wrapping the text.

        Now, based on the screen size, i position my content elements with a size that stretches the elements at all resolutions or that places them under each other if the screen is too small. The problem was in the unpredictable behavior of resizing. If you don't fix sizes you can still get unwanted layout anomalies, even with css.

          Hi,
          why don't save the screen size in a session variable in any previous page?

          I've succesfully used this approach, just saving in a session the screen size when the user login.

          So, when I need, I can do the check at php time just reading the value stored.

          I hope this helps. Bye!

            Write a Reply...