【问题标题】:How to hide ads on small screens如何在小屏幕上隐藏广告
【发布时间】:2016-04-01 07:04:37
【问题描述】:

我希望在我的网站的移动版本上隐藏一个广告。我想这样做。

<script>
    if(screen.width > 900){
        "here call the script that is ad"
    }
</script>

我的广告脚本也是 js 脚本,但它不在我的域中,所以我不能使用 ajax 调用来调用它。任何帮助表示赞赏。 我的广告代码如下所示

<script src='//url..'> </script> 

【问题讨论】:

    标签: javascript mobile web ads


    【解决方案1】:

    为什么不直接使用 CSS 和媒体查询呢?

    将添加的内容包装在一个 DIV 中(比如说 &lt;div id="ad_1"&gt;...[link to your ad or content]...&lt;/div&gt;)并添加到您的样式表中

    @media only screen and (max-width: 900px) {
      #ad_1 { display: none; }
    }
    

    【讨论】:

    • 仍然,它必须在某种包装 div 中,通常有一个 ID 或至少一个类(使用浏览器开发工具找出)。找到该 ID 或类并为其添加该 CSS 规则...
    猜你喜欢
    • 2022-06-24
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    相关资源
    最近更新 更多