Browser Screensize detection

<?php
 
  if (!defined(SCREEN_WIDTH) && !defined(SCREEN_HEIGHT)) {
    if (is_numeric($_GET['sx']) && is_numeric($_GET['sy'])) {
      echo "<SCRIPT LANGUAGE=\"JavaScript\"><!--\r\n";
      echo "  window.onresize = \"self.location.search += '&sx=' + window.innerWidth + '&sy=' + window.innerHeight;\";\r\n";
      echo "  // -->\r\n";
      echo "</SCRIPT>\r\n";
      define(SCREEN_WIDTH, $_GET['sx']);
      define(SCREEN_HEIGHT, $_GET['sy']);
    } else {
      echo "<SCRIPT LANGUAGE=\"JavaScript\"><!--\r\n";
      echo "  window.onerror = null;\r\n";
      echo "  if (self.location.search.indexOf('sx')==-1 && self.location.search.indexOf('sy')==-1) {\r\n";
      echo "    var add='';\r\n";
      echo "    if (self.location.search.length>1) { add += '&'; }\r\n";
      echo "    add += 'sx=' + window.innerWidth + '&sy=' + window.innerHeight;\r\n";
      echo "    self.location.search += add;\r\n";
      echo "  }\r\n";
      echo "  // -->\r\n";
      echo "</SCRIPT>\r\n";
      define(SCREEN_WIDTH, SCREEN_WIDTH_FALLBACK);
      define(SCREEN_HEIGHT, SCREEN_HEIGHT_FALLBACK);
    }
    if (defined('SESSIONS')) {
      $_SESSION['sx'] = SCREEN_WIDTH;
      $_SESSION['sy'] = SCREEN_HEIGHT;
    }
  }
 
?>

 
snippets/php/screensizedetection.txt · Last modified: 2008-07-15 22:20.53 by mbirth
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki Contents powered by Club-Mate Contents powered by BassDrive.com Labelled with ICRA