简体   繁体   中英

php to detect browser window width then include proper php file

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 }  ?>

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.

It's against best practices to server different content based on platform. In fact Google will rank your site differently based on this.

You want to use a responsive framework to handle different browser sizes. Here is a list of a few that I would recommend:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM