Strategies for preventing mobile browsers from downloading Google AdSense ads on a responsive website

Utilizing a media query, I've set one Div to display:none which contains AdSense code. However, I'm looking to display another AdSense Ad located in a different DiV with display:block.

Seeking clarification on the following: Will setting display:none prevent the Ad request from being sent to Google, or simply stop it from downloading the Ad from Google? My dilemma is that I want to display a fourth AdSense Ad, but displaying 4 ads goes against AdSense policy.

Answer №1

display:none on the parent div does not stop ad requests from that ad unit:

<div style="display:none">
  <ins class="adsbygoogle adslot_1" ... ></ins>
</div>

This goes against the AdSense policy regarding hiding ads: "Hiding ad units at anytime (e.g., display:none), unless you're implementing a responsive ad unit."

To actually prevent ad requests, we should apply display:none to the AdSense ins tag itself:

<style type="text/css">
.adslot_1 { display: inline-block; width: 320px; height: 50px; }
@media (max-width: 400px) { .adslot_1 { display: none; } }
@media (min-width: 500px) { .adslot_1 { width: 468px; height: 60px; } }
@media (min-width: 800px) { .adslot_1 { width: 728px; height: 90px; } }
</style>
<ins class="adsbygoogle adslot_1"
  data-ad-client="ca-pub-1234"
  data-ad-slot="5678"></ins>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>

This is an advanced feature called "Hiding an ad unit". In the scenario where the viewport is under 401px, the above code will insert a

<!--No ad requested because of display:none on the adsbygoogle tag-->
comment within the ins tag instead of displaying the advertisement.

If you want to demonstrate how to "move" AdSense ads, my JSFiddle example titled "How to 'move' AdSense ads" might be what you're looking for - "I wanted to show another AdSense Ad which is in another DiV with display:block". (Move the vertical border to see the ads "moving".)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Populate any void area when <td> is not occupied in <tr>

I have a table with two rows and columns. If one of the columns is empty, it should move up to the upper row. For example: |td1 | td2| |td3 | | |td5 | td6| This is what I want: |td1 | td2| |td3 | td5| |td6 | | Below is the code snippet that ...

What could be causing bundle.js to remain in a pending status on my website?

Whenever I try to open a page from my project, the browser keeps showing loading forever and in the network tab, the status of bundle.js is pending. (Interestingly, if I open other routes of the project, everything works fine). If I remove all product var ...

Hover over a row in one table to modify the appearance of another row in a different table

Is there a way to change the appearance of rows in one table when hovering over rows in another table that are related? You can find a JSFiddle link illustrating what I am trying to achieve. Here is an example of the code: table#table1 #el1:hover + ta ...

Position navbar contents at the top of the screen

As I delve into learning Bootstrap4, I have come across the following snippet of HTML code: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> ...

Email design is compromised at unconventional screen sizes

My responsive HTML email is experiencing a strange issue where it breaks between a 20px resolution difference before reaching the media query. Specifically, between 600px and 620px, I am puzzled as to why this is happening. Everything has been thoroughly c ...

Restrictions on the height of Bootstrap 4 .card are determined by the height of the parent when

I am trying to create a card deck that contains multiple cards displayed side by side, even on mobile devices, with both horizontal and vertical scrolling capabilities. The parent container of the cards has a fixed height, however, I am struggling to adju ...

Additional blank space beside a webpage

@font-face { font-family: 'Open Sans'; font-style: normal; font-weight: 300; src: local('Open Sans Light'), local('OpenSans-Light'), url(https://fonts.gstatic.com/s/opensans/v13/DXI1ORHCpsQm3Vp6mXoaTRampu5_7CjHW5spxoeN ...

What is the best way to position three DIVs next to each other within another DIV while aligning the last DIV to the right?

I need help formatting a simple list item with three DIVs. The first DIV should be left justified, the second should be able to grow as needed, and the third should be right justified. I currently have them stacked side by side, but can't get the last ...

What is the procedure to reduce my final search result by 1?

When the search is triggered, I want to filter the images by name. However, the issue arises when trying to make everything disappear on filter addition. <ul id="list2"> <li class="in2"> An extra number is added ...

The icon must be aligned to the right and able to adapt to different

I'm attempting to align a Font Awesome icon to the right while keeping an input field aligned to the left on the same line. Both elements should be responsive and maintain their positions. I've created a sandbox and an image showcasing how it cu ...

Bootstrap Navbar and Flexbox items not aligned properly at the ends

Struggling to align items on Navbar? Here is my current setup: https://i.sstatic.net/Doc9A.jpg I'm trying to position the flag image next to the toggler button, only when the screen reaches 992px breakpoint. It seems like Bootstrap Stylesheet is us ...

A guide to the bottom border of text inputs in React Native

Trying to create a borderless text input has been a challenge for me. After applying the necessary properties, a bottom border line in black color appeared. View image of text input I am looking for a way to remove this border completely. import { TextIn ...

My webpage layout doesn't quite accommodate my content, so I need to adjust it to be more zoom

Why does the page container load bigger than the html/body container in mobile mode, as shown in the photo? https://i.sstatic.net/fD1N4.png Here is my CSS: html { margin-top: 48px; width: 100%; } body { margin: 0; width: 100%; background: ...

Can a div be aligned in the center with an "absolute" parent element?

<style type="text/css"> .square { width:251px; height:207px; border: 1px solid #d6d6d6; -webkit-box-shadow: 1px 1px 3px rgba(0,0,0,.1); -moz-box-shadow: 1px 1px 3px rgba(0,0,0,.1); box-shadow: 1px 1px 3px rgba(0,0,0,.1); ...

The Google Language Translator disregards the formatting

Currently, I am in the midst of developing a website with Wordpress and have successfully integrated Google Language Translator. Everything seems to be working well, except for one issue - when I translate the content, it alters the font size. Prior to tra ...

Aligning Text and images perfectly in a DIV container, and beyond

I am trying to center or align text and images at the bottom of a couple of tags, but vertical-align doesn't seem to be cooperating. Another challenge I have is creating a horizontal menu with a start image (e.g. menutop.png), followed by a filler ( ...

Auto-selecting the first item in a CSS menu when the switcher is tapped on mobile devices

Struggling with a responsive CSS menu on my website, . The switcher on mobile seems to automatically click the first item in the menu (Home) as I open it, redirecting me instantly. When setting the link to "#" everything is fine, but then I lose the home l ...

Switch from scrolling the entire page to scrolling within a single div

Whenever I click on an element on my webpage, a modal window with a fixed position appears. The issue I am facing is that when I scroll using the mouse or touch gestures on my phone or tablet, the entire page scrolls instead of just the content within the ...

What could be causing transition to not be recognized as an element in HTML?

<template> <header> <nav class="container"> <div class="branding"> <router-link class="header" :to="{name : 'Home'}">>FireBlogs</router-link> </div& ...

Animating content through CSS and jQuery to reveal its unfolding effect

Just stumbled upon the amazing quote-expansion animation in the OSX Mail app and I am completely impressed. I am on a mission to bring that same magic to the web (or at least close to it), but unsure if anyone has done something similar yet. A couple of ...