donglu9134 2015-02-20 18:00
浏览 68

php检测浏览器窗口宽度然后包含适当的php文件

I'm a fairly php and javascript newb, so I'm having difficulty getting this to work, or finding and similar question/answer here.

Here's my newb php to show show what I want to accomplish. I know jquery or js should be used to find the browser window width, but I'm not sure how to implement this - I need to determine my fake if(browser_is_big()) function:

<?php if (wp_is_mobile()) { //is this a mobile device? ?>
   <!--Then no banner ad here.-->
<?php } else { //if not mobile, then display desktop banner ad ?>
  <?php if (browser_is_big('browser window width is greater than 1320')) {
        include 'banner_790_width.php';
        } else {
        include 'banner_468_width.php'; 
    }?>
<?php }  ?>
  • 写回答

2条回答 默认 最新

  • dongqian3750 2015-02-20 18:37
    关注

    Although i see what you are trying to do, I wouldnt recommend going down this design path.

    Your backend code (in this case php) should be agnostic to the parameters of the data, it shoudl just work all objects of that type in the same way. The front-end should be responsible to draw the data in a way that works best for the browser and the client.

    What im trygin to say is, if you have a fluid template, just passing the data from the backend should be enough as your template will react to the size and setting of the client using JS and CSS. That way, you keep your front end and back end code seperate.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog