0

I'm trying to build a PHP page that a) detects the users screen size and either echo's a URL (download document) if the screen size is MOBILE or includes a php page if COMPUTER.

That being said I cannot seem to find the right match... I saw one done with PHP while storing cookies, but that's not practical as you need to reload the page to store cookies before the page reacts properly.

Here is what I've been trying:

<?php
   $callget_res_page_name = $REQUEST_URI;
   $GLOBALS[callget_res_page_name] = $callget_res_page_name;
?>


<script>
  if (document.write("+screen.width+") > 768) {
     $("#mailDiv").load('menu.html');
  }
  else {
     document.write('<h1><a href='Menu.pdf'>Download the PDF Menu</a</h1>');
  }
</script>

Any thoughts on what I'm doing wrong or how else I could attempt to accomplish this?

freedev
  • 25,946
  • 8
  • 108
  • 125
SiREKT
  • 37
  • 6
  • 1
    What does `document.write("+screen.width+") > 768`? Better do `screen.width > 768` you dont have to print it to the document. – JustOnUnderMillions Feb 23 '17 at 15:36
  • 1
    Lookup here: http://stackoverflow.com/questions/3437786/get-the-size-of-the-screen-current-web-page-and-browser-window – JustOnUnderMillions Feb 23 '17 at 15:37
  • I think you would be better off using some sort of existing package or module to do this. For example: http://mobiledetect.net/. If you are attempting to make different versions of site/page for mobile and desktop, then I would suggest researching adaptive web design. There are lots of existing frameworks and examples available. All of the hard work has already been done. – clarmond Feb 23 '17 at 15:40

0 Answers0