2

我在响应式设计方面遇到了 AdSense 问题。我发现的一种解决方案是,如果窗口大小不够大,则根本不加载它们。所以我想我会用广告代码、容器等创建一个单独的 php 文件,然后将其包含在页面上。但是,如果窗口宽度为 720 像素或以上,我不知道如何仅包含此文件,否则不包含此文件。也许,可以以某种方式使用 javascript,但不确定它如何与所有 dom 和 php 包含一起工作。

4

2 回答 2

4

您可以尝试以下方法:

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

#place_holder_div是您的 html 文件中的一个 div。语法是Jquery,但如果您愿意,当然可以使用纯 javascript。代码查看屏幕宽度,如果大于 720 像素,则将 php 文件file_from_server.php(将包含您的广告)加载到占位符 div 中。

于 2013-04-23T15:09:58.940 回答
1

了解客户端的窗口或屏幕大小的唯一方法是使用 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

在检查完这些之后,您可以对相关文件进行 HTTP 请求。然而,这可能不是最好的解决方案,因为用户实际上可以在任何给定时间更改上述任何大小。

于 2013-04-23T15:13:01.833 回答