![]() ![]() It works with those that block access to the ad server, as well as those that spoof it. Below is the only good solution I've found and it works with even the best ad blocker extensions (like uBlock Origin, Adblock Plus) and in-browser ad blockers (like Brave, Opera) that I've tested. ![]() The dimensions (and I guess visibility, as a hidden object has no height or width?) of the iframeĪnd the styles: div#myTestAd, iframe#adServerĪd blockers are very smart these days, they can even spoof ad server requests with redirects and return fake responses.That the content of the second test div is "check", as it would have been if the advertimsent.js was not blocked.The dimensions and visibility of the first test div.the markup is loaded, we add the iframe to the document also. $(document).ready(Īnd then the ad blocker detection script which combines everything $(document).ready(function()Īlert("You're using ad blocker you normal person, you!") Although it seems like you're doing the same as before, you are actually checking for the file ( advertisement.js) itself being loaded, not the output. In advertisement.js you should append something to the document which we can check for later. I used a div with a bait name as well as an externally hosted image with the text "Advert" and in dimensions used by AdSense (thanks to !). On the page your are running the checks add: (I am using jQuery) Īnd add the following anywhere else on the page: Maybe it's over the top or paranoid but it covers for ad blocking systems that block only one or two out of the selection and therefore may not have been covered had you only done the one check. After looking here and elsewhere I surmised that the main three client side checks for indirectly detecting an ad blocker were to check for blocked div/ img, blocked iframes and blocked resources (javascript files). Checking the type of variable after a certain time can tell you if the script was loaded.ĭespite the age of this question, I recently found it very useful and therefore can only assume there are others still viewing it. Update uBlock Origin loads their own ads-prebid.js that reverts the trick described in this answer (proud!), their file contains the following: (function() when it executes. Update Call this variable something else, see below! var canRunAds = true This is the only line of code in that file. I added a small js file to my webroot with the name prebid-ads.js AdBlock blocks all URLs containing the word "ads" or "prebid". I've been running it in production for a few years. My solution is not specific to a certain ad network and is very lightweight. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |