dtry54612 2015-11-09 19:15
浏览 41

检测用户屏幕宽度的最佳做法是什么?

In my joomla website, I have a module that outputs 1 item by default, in its help.php file, there is something like

$items = 1;
$db->setQuery($query, 0, $items)

Now I want to detect if users' screen width is less than a certain value, if yes, then get only 1 item, else get 4 items. What is the best practice to do it?

I can just set $items to 4 and use javascript to eliminate the other 3 items, but this is not a perfect solution because excessive data will be downloaded. My questions are: 1) can PHP alone detect client's screen width? 2) If no and I have to use javascript/ajax, I am thinking add

<script>
    var w = screen.width;
    href = location.href;
    if (location.search){
       href = href + '&screenWidth=' + w;
    } else
    href = href + '?screenWidth=' + w;
</script>

to every page and use $_GET['screenWidth] to get the screen width value in the helper.php file, is this a good practice? Is this gonna mess up with output buffer sif there is any) set by my CMS(joomla)?

  • 写回答

2条回答 默认 最新

  • doutiaoku4495 2015-11-09 19:22
    关注

    Just give the items a class with CSS that will hide them on mobile.

    @media(max-width: 768px){
        .some-class{
            display: none;
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向