Web Analytics Made Easy -
StatCounter JavaScript/PHP - CodingForum


No announcement yet.


  • 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

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


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


      • #4
        whilst you can not rely on anyone having javascript .. you can pass the width and height from javascript to PHP...

        PHP Code:
        function have_script(){
        <body onload="have_script()">
        "$_GET[height] :: $_GET[width]";
        "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
          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])?>' ;

          Thanks for your support


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


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