Web Analytics Made Easy -
StatCounter JavaScript/PHP - CodingForum

Announcement

Collapse
No announcement yet.

JavaScript/PHP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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
    My Website
    010100010011110101110100011011110111000001101000

    Comment


    • #3
      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!

      Comment


      • #4
        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)

        Comment


        • #5
          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

          Comment


          • #6
            Forget to say that the previous code does not work.

            Comment


            • #7
              Hello I would like to know how can I save in a php variable the result of a javascript function Thank you

              Comment

              Working...
              X