Announcement

Collapse
No announcement yet.

How to get screen resolution in SC8 ? width and height of the screen ?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get screen resolution in SC8 ? width and height of the screen ?

    Hello, How i can get the width and height of the screen?
    There is a function in SC8 that does this ?
    I looked in the help of script case but did not find anything.
    Thanks if anyone can help me.

  • #2
    you can't get that information use php you need Javascript for that...

    Comment


    • #3
      Hello kafecadm thanks for your reply.

      I tried to use this Javascript code, but i have another problem:

      I insert this code in: OnApplicationInit

      $Width_Screen="<script >document.write(screen.width)</script>";
      $Hight_Screen="<script >document.write(screen.height)</script>";

      echo 'The Screen Resolution is: '.$Width_Screen.' x '.$Hight_Screen;

      The code works fine and print the correct value: The Screen Resolution is : 1920 x 1080

      Now I would like to load the two values (Width and Hight) in two numeric variables:

      I try to make this with this code but doesn' t work:

      $Width_int=(int)$_GET[$Width_Screen];
      $Width_int=(int)$_GET[$Hight_Screen];


      Press two errors on the screen and does not fill the values in the variables:

      Errore
      Undefined index: 1920
      Errore
      Undefined index: 1080


      How i can solve the problem ?
      Thanks you very much for your reply

      Comment


      • #4
        That makes sense.. $_GET is for getting values from the requested url string. Since $Width_Screen is 1920 this translates to:
        $Width_int=(int)$_GET[1920]; therefor your error.
        The index is undefined makes total sense.
        You already have the values in javascript as screen.width so you could send the data using jquery.
        So a little search on stackoverflow gives you several solutions including this:
        http://stackoverflow.com/questions/1...tion-using-php

        In reality you can not get the screen resolution but only the browser window size.
        So basically you need to pass the values of the variables you already properly got using jquery (or something else) to your php.

        Comment


        • #5
          Thanks for your response, I saw the post on StackOverflow and everything is very clear.
          Now the 'only problem and where i enter the jquery code in SC8.
          I tried the manual is SC8, but it is not very clear, unfortunately i have to say that the manuals SC8 are very scarce and many times without examples.

          What section of SC8 insert this function jquery?

          $(function() {
          $.post('some_script.php', { width: screen.width, height:screen.height }, function(json) {
          if(json.outcome == 'success') {
          // do something with the knowledge possibly?
          } else {
          alert('Unable to let PHP know what the screen resolution is!');
          }
          },'json');
          });

          If you can give me an example I would be very grateful.
          Thanks

          Comment


          • #6
            place that code in the onApplicationInit event. using something like

            PHP Code:
            echo "
            <script>
            $(function() {
               $.post('some_script.php', { width: screen.width, height:screen.height }, function(json) {
                  if(json.outcome == 'success') {
                  // do something with the knowledge possibly?
                  } else {
                     alert('Unable to let PHP know what the screen resolution is!');
                  }
               },'json');
            });
            </script>
            "

            regards
            Last edited by kafecadm; 06-18-2015, 11:41 AM. Reason: fixing a coding error =P

            Comment


            • #7
              I could have guessed that our resident javascript jedi master knew the right place.

              Comment


              • #8
                :P so... did he? lol.

                Regards

                Comment


                • #9
                  I finally solved this problem, thanks for helping me and especially to kafecadm and rr.
                  I am very happy to use Script Case 8, however the manuals are unclear and with a few examples, but surely thanks to this beautiful forum will manage to solve various problems.
                  I wait anxiously distributing of Script Case 8.1, I wish the whole development team Script houses continue their wonderful work, I hope that we can find in version 8.1 the improvements in 'responsive interface, and developers Script Case find some time to improve the manual.


                  The final code I used is this, it works very well:

                  echo "
                  <script>
                  $(function() {
                  $.post('some_script.php', { width: screen.width, height:screen.height }, function(json) {
                  if(json.outcome == 'success') {
                  // do something with the knowledge possibly?
                  //alert('Unable to let PHP know what the screen resolution is!');
                  alert('Settata funzione jquery !');
                  } else {
                  alert('Unable to let PHP know what the screen resolution is!');
                  }
                  },'json');
                  });
                  </script>
                  ";


                  if(isset($_SESSION['screen_width']) AND isset($_SESSION['screen_height'])){
                  //echo 'User resolution: ' . $_SESSION['screen_width'] . 'x' . $_SESSION['screen_height'];
                  $SG_Width=intval($_SESSION['screen_width']);
                  $SG_Height=intval($_SESSION['screen_height']);
                  } else if(isset($_REQUEST['width']) AND isset($_REQUEST['height'])) {
                  $_SESSION['screen_width'] = $_REQUEST['width'];
                  $_SESSION['screen_height'] = $_REQUEST['height'];
                  $SG_Width=intval($_SESSION['screen_width']);
                  $SG_Height=intval($_SESSION['screen_height']);
                  header('Location: ' . $_SERVER['PHP_SELF']);
                  } else {
                  echo '<script type="text/javascript">window.location = "' . $_SERVER['PHP_SELF'] . '? width="+screen.width+"&height="+screen.height;</script>';
                  }


                  Regards
                  Last edited by multisystems2; 06-18-2015, 08:45 PM.

                  Comment


                  • #10
                    Nicely Done dude.

                    Regards

                    Comment

                    Working...
                    X