How to detect Adblock on my website?

2019-01-01 07:23发布

I would like to be able to detect if the user is using adblocking software when they visit my website. If they are using it, I want to display a message asking them to turn it off in order to support the project, like this website does.

If you enter to that site and your browser has some kind of adblock software enabled, then the site instead of showing the actual ads shows a little banner telling the users that the ad revenue is used for hosting the project and they should consider turning Adblock off.

I want to do that on my website, I'm using adsense ads on it, How can I do that?

45条回答
一个人的天荒地老
2楼-- · 2019-01-01 08:29

I know this is already answered, but I looked at the suggested sample site, and I see they do it like this:

<script type="text/javascript">
if(document.getElementsByTagName("iframe").item(0) == null) {
    document.write("<div style="width: 160px; height: 600px; padding-top: 280px; margin-left: 5px; border: 1px solid #666666; color: #FFF; background-color: #666; text-align:center; font-family: Maven Pro, century gothic, arial, helvetica, sans-serif; padding-left: 5px; padding-right: 5px; border-radius: 7px; font-size: 18px;">Advertising seems to be blocked by your browser.<br><br><span style="font-size: 12px;">Please notice that advertising helps us to host the project.<br><br>If you find these ads intrusive or inappropriate, please contact me.</span><br><img src="http://www.playonlinux.com/images/abp.png" alt="Adblock Plus"></div>");
};
</script>
查看更多
步步皆殇っ
3楼-- · 2019-01-01 08:29
不流泪的眼
4楼-- · 2019-01-01 08:29
floor|EikYcPAgeLis|String||margin|else|fromCharCode|this|top||charAt
查看更多
登录 后发表回答