How to detect ad blocking and show a message?

别说谁变了你拦得住时间么 提交于 2020-01-15 11:42:44

问题


So there is a lot of conflicting posts and mostly outdated info on this, how exactly would I detect people blocking google ads?

My ads for example are shown like this:

        <div class="row gol-news-ad hidden-tablet hidden-phone">
            <div class="span9">
                <div class="alert alert-info text-center">
                <script type="text/javascript"><!--
                google_ad_client = "ca-pub-7221863530030989";
                /* gol top above news big */
                google_ad_slot = "5565571944";
                google_ad_width = 728;
                google_ad_height = 90;
                //-->
                </script>
                <script type="text/javascript"
                src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                </script>
                </div>
            </div>
        </div>

Would there be a way to show a message like "Please support us and don't block our ads!" if they have blocked them?

I've tried adding:

$(window).load(function() {
    if(typeof(window.google_render_ad)=="undefined") 
    { 
        var thep = document.getElementById('mainad');
        var content = document.createTextNode("Please disable adblocker!");
        thep.appendChild(content);
    }
}

And wrapping the adcode in a "mainad" p element to no luck.

来源:https://stackoverflow.com/questions/16588319/how-to-detect-ad-blocking-and-show-a-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!