Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 1.87 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to load a diferrent php file dynamically based on the browser window's width using jQuery or any other method
  2. function adjustStyle(width) {
  3.     width = parseInt(width);
  4.     if (width < 701) {
  5.         $("#size-stylesheet").attr("href", "css/narrow.css");
  6.     } else if ((width >= 701) && (width < 900)) {
  7.         $("#size-stylesheet").attr("href", "css/medium.css");
  8.     } else {
  9.        $("#size-stylesheet").attr("href", "css/wide.css");
  10.     }
  11. }
  12.  
  13. $(function() {
  14.     adjustStyle($(this).width());
  15.     $(window).resize(function() {
  16.         adjustStyle($(this).width());
  17.     });
  18. });
  19.        
  20. <link rel="stylesheet" type="text/css" href="main.css" />
  21. <link id="size-stylesheet" rel="stylesheet" type="text/css" href="narrow.css" />
  22.        
  23. function setLocation(url) {
  24.    if (window.location.href.indexOf(url) === -1)
  25.       window.location = url;
  26. }
  27.  
  28. function reloadPage(width) {
  29.     width = parseInt(width);
  30.     if (width < 701) {
  31.         setLocation("yournarrowpage.php");
  32.     } else if (width < 900) {
  33.         setLocation("yourmediumpage.php");
  34.     } else {
  35.         setLocation("yourwidepage.php");
  36.     }
  37. }
  38.  
  39. $(function() {
  40.    reloadPage($(this).width());
  41.    $(window).resize(function() {
  42.        reloadPage($(this).width());
  43.    });
  44. });
  45.        
  46. function setLocation(url) {
  47.    $("selector for the element to reload").load(url);
  48. }
  49.        
  50. $(document).load(function() {
  51.     var $width = $(window).width()
  52.     if($width < 701)
  53.         window.location = 'narrow.php'
  54.     else if($width < 900)
  55.         window.location = 'medium.php'
  56.     else
  57.         window.location = 'wide.php'
  58. })
  59.        
  60. if(stristr($_SERVER['HTTP_USER_AGENT'], 'Mozilla/5.0(iPad;')) {
  61.      // probably an iPad
  62.      require('ipad.php');
  63.      //Or maybe the below might serve you better:
  64.      /*
  65.      header('Location:ipad.php');
  66.      die();
  67.      */
  68. }
  69.        
  70. if (width < 701) {
  71.     $.get('yourlayoutfor701.php', function(data) {
  72.     $('#your_layout').html(data);  
  73.     });
  74.  }