简体   繁体   English

仅在某些屏幕分辨率下包含php文件

[英]include php file only at certain screen resolutions

I'm having issues with adsense on responsive design. 我在响应式设计方面遇到了问题。 One solution I found is to not load them at all if window size is not big enough. 我找到的一个解决方案是,如果窗口尺寸不够大,根本不加载它们。 So I thought I would create a separate php file with advertisement code, container etc... and than include it on a page. 所以我想我会用广告代码,容器等创建一个单独的php文件......而不是将它包含在页面上。 However, I can't figure out how to only include this file if, lets say, window width is 720px or above, else don't include this file. 但是,如果窗口宽度为720px或更高,我不知道如何只包含此文件,否则不包含此文件。 Perhaps, javascript can be used some way, not sure how it will work with all the dom and php includes though. 也许,javascript可以用某种方式,不知道它将如何适用于所有的dom和PHP包括虽然。

You can try something like: 您可以尝试以下方式:

<script language=javascript>
    if (screen.width >= 720 ) 
         $('#place_holder_div').load('file_from_server.php');
</script>

Here #place_holder_div is a div in your html file. 这里#place_holder_div是你的html文件中的div。 The syntax is Jquery but of course you can use plain javascript if you wish. 语法是Jquery但是如果你愿意,你当然可以使用普通的javascript。 The code looks at the screen width and if greater than 720 pixels, loads the php file file_from_server.php (which will contain your ad) into the placeholder div. 代码查看屏幕宽度,如果大于720像素,则将php文件file_from_server.php (包含您的广告)加载到占位符div中。

The only way to know what the window or screen size of a client is, is by using JavaScript. 了解客户端窗口或屏幕大小的唯一方法是使用JavaScript。

window.innerHeight; // Available height of the browser for the document
window.innerWidth; // Available width of the browser for the document
window.outerHeight; // Browser height
window.outerWidth; // Browser width
window.screen.height; // Screen height
window.screen.width; // Screen width

After inspecting these, you could do a HTTP request for the relevant file. 检查完这些后,您可以对相关文件执行HTTP请求。 It is, however, probably not the best solution since the user can actually change any size mentioned above at any given time. 然而,它可能不是最佳解决方案,因为用户实际上可以在任何给定时间改变上述任何尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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