简体   繁体   中英

Disable google AdSense on Mobile Devices using JavaScript

I want to disable Google ADS in Mobile devices.

At the minutes I have this

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
}else
{
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="*****"
     data-ad-slot="****"
     data-ad-format="***"></ins>
}
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

But it's not working.

I'm struggling to find the code to disable Google ADS in Mobile devices.

Any help or other ideas would be much appreciated.

Your code should work with some syntax changes,

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
isMobile = false;
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
 isMobile = true;
}
if(isMobile){
  $(".adsbygoogle").hide();
}else{
$(".adsbygoogle").show();
}
</script>

<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

Your html,

    <ins class="adsbygoogle"
         style="display:block"
         data-ad-client="*****"
         data-ad-slot="****"
         data-ad-format="***"></ins>

Give it a try, this should work.

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