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 7 of 7

Thread: JavaScript/PHP

  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Regina, Saskatchewan, Canada
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScript/PHP

    I currently program my entire web site in PHP. However, recenty I needed to detect the screen size and subtract a certain amount from it, then create a table that wide. BUT, unfortunately it doesn't work.

    Can someone please help me on how to detect a user's screen size with PHP?
    Jared Brandt
    IKinsler

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think it can't be done using only PHP. As your subject says, you might need JavaScript.

    PHP is executed on the server before any information of the user (like screen size) is sent to PHP.

    Mzzl, Chris

  • #3
    New Coder
    Join Date
    Jun 2002
    Location
    Paris, France
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You should use relative (%) values rather than absolute :

    For example : if you want the table to be half the size of the screen do :

    <table width="50%">
    I don't suffer from insanity, I enjoy every single minute of it!

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    whilst you can not rely on anyone having javascript .. you can pass the width and height from javascript to PHP...

    PHP Code:
    <script>
    function have_script(){
    <?if(!$_GET[width]){?>
    location.href="<?=$_SERVER[PHP_SELF];?>?width="+screen.width+"&height="+screen.height;
    <?}?>
    }
    </script>
    <body onload="have_script()">
    <?if($_GET[height]){
            echo 
    "$_GET[height] :: $_GET[width]";
        }else{
            echo 
    "javascript not available";
        }
    ?>
    so that reloads the page with the $_GET[width] && $_GET[height] variables available to PHP, non-js browsers will just ignore it so you can not depend on the values being available.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    New to the CF scene
    Join Date
    Nov 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How to call to a function in javascript sending a numerical parameter? This parameter will be used in php code inside javascript:

    call the javascript function:
    <A href='javascript:void(0)' onClick='ShowFAQ(25)'>text</A>

    <script type="text/javascript">
    function ShowFAQ(faqid){
    window.document.labeltitlefaq.innerText='<?php echo($arrayFAQtitle[faqid])?>' ;
    }
    </script>

    Thanks for your support

  • #6
    New to the CF scene
    Join Date
    Nov 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Forget to say that the previous code does not work.

  • #7
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello I would like to know how can I save in a php variable the result of a javascript function Thank you


  •  

    Posting Permissions

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