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 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Screen res varible for php?

    I know that being server side, php cannot detect screen res. But I am wondering If I could use Javascript to detect the screen res and then use PHP to load the appropriate include ().
    What I have is a site that ports well between different resolutions apart from its header (which contains the main nav and search input box) which hangs off the right hand side. As the header is an include I figure that I could make two versions of this include. And load the appropriate one depending on a screen width varible say < 1024 or > 1024.

    So I have the following javascript to detect screen res width
    Code:
    <script language='Javascript'>
    <!--
    if (screen.width <= 800){document.location="8by6/index.php";}
    else if (screen.width <= 1024){document.location="10by24/index.php";}
    if (screen.width > 1024){document.location="10by24/index.php";}
    //-->
    </script>
    But this is just telling the browser to go to a certain page in a certain dir.
    How can I alter the
    {document.location="10by24/index.php";} element
    to a varible that PHP can pick up on and use acoridingly ?

    Crowds
    PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Would this establish the variables ready for PHP to call them ?
    Code:
    <script language='Javascript'>
    <!--
    if (screen.width <= 800){var sr = "800";}
    else if (screen.width <= 1024){var sr = "1024";}
    //-->
    </script>
    Crowds
    PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,472
    Thanks
    0
    Thanked 634 Times in 624 Posts
    The only way Javascript can provide information to PHP is either by loading a new page with the values passed in the search string or by using Ajax.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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