简体   繁体   中英

Hide AdSense or GoogleAdmanager ad unit when clicked

I am trying to hide a div containing an AdSense unit when the ad itself is clicked. I am trying with onclick="... with no success.

It is not fraud and the ad do not cover any kind of content. I just want to hide this particular ad unit if clicked and compress the div. Thank you for your support.

Andrea

SOLVED:

First the ads:

<body-5 id="target">
<!-- /XXXX/leaderboard -->
<div id='div-gpt-ad-XXXXXXXXXXX-0' class="adsbygoogle" style='height:90px; width:728px;'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-XXXXXXXXXXX-0'); });
setInterval(function(){googletag.pubads().refresh([slot1]);}, 60000);
</script>
</div>
</body-5>

Then the script to hide the ads:

<!-- HIDE ADS -->
<script src="/script/iframe/jquery.iframetracker.js"></script>

<script type="text/javascript">
jQuery(document).ready(function(){
interval_id = window.setInterval(function() {
//check if iframe exists
if( jQuery('.adsbygoogle div').length > 0 ) {
    jQuery('.adsbygoogle div').iframeTracker({
        blurCallback: function(){
// Do something when the iframe is clicked
    $('#target').slideUp( 2000 );
        }
    });
    //clear the interval
    // clearInterval(interval_id);
    }
},300);
});
</script>

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