Take the 2-minute tour ×

I've written a web app that uses an ad banner on the side to support free accounts. Problem is, since the ad is loaded in its own <div>, it's relatively easy to go into developer/debug console in any modern browser and either remove the div or resize the ad to 0px using CSS overrides (the users might do this to gain more real-estate in the app workspace). To prevent this, I was considering checking periodically if the properties of the div with the ad change at all (including CSS style), and if they do, reload the page. Since I'm relying on a canvas element for some drawing, a reload would be relatively annoying to the user since it would clear the canvas, so I don't want to do it unless the advertisement was tampered with.

I've seen some similar questions about tracking DOM changes where people suggest using mutation events. However, based on the answers, it doesn't seem like the support is there in all browsers yet (then again, the threads I've seen are from 2008 and 2009, so things might have changed since then).

Another alternative I was considering is just reading in offsetWidth, offsetHeight, offsetTop, offsetLeft of the div with the ad after the page finishes loading, and keep comparing them periodically against current values (there is not a whole lot you can do to make the div go away if you can't move it).

What do you guys suggest?

share|improve this question
Web development would be no way near as fun if you couldn't tamper with the DOM. –  mrk Jun 15 '11 at 3:55
If the user might be doing this to gain more real estate, could you prevent that (fix the width of the usable area) to take away that reason? –  Don Zacharias Jun 15 '11 at 4:05
Thanks @Don, that's what I ultimately ended up doing. I have several divs aligning to the size they would take up if the ad was there, so even if the user removes the ad, there would be nothing to gain unless either js code is modified as well or user modifies multiple other divs and does not resize the window afterwards. While other people bring up very valid points, I don't agree that they have answered the question. If I StackOverflow let me accept comments as a solution, I would accept your comment :) –  Alexander Tsepkov Jun 15 '11 at 19:03
Glad I could help! I went with a comment because I figured I wasn't technically answering your question. –  Don Zacharias Jun 15 '11 at 19:17
add comment

2 Answers

You'll never stop someone who is comfortable enough with the DOM inspector from doing that. It's not even worth the cat and mouse game. 99.999% of users would probably call tech support if they accidentally accessed the DOM inspector.

share|improve this answer
+1 If you can tamper with the DOM in this way, you can also manipulate the Javascript that tries to detect manipulation. –  deceze Jun 15 '11 at 3:05
+1 You shouldn't even call it 'tampering' - you served the user the DOM, it's theirs to do what they like with in their client. Like these guys say - very few users will even consider that removing the ads is possible. –  Beejamin Jun 15 '11 at 3:12
True, but tweaking the DOM takes a few seconds (it's one of the outer-most divs), tweaking the javascript actually requires that the user study the code (which is usually not worth the effort for an ad that's not that intrusive anyway). I understand that preventing this completely is impossible, but I was hoping to add a simple check to prevent an obvious exploit. –  Alexander Tsepkov Jun 15 '11 at 3:15
So check the bounds, then they will just move it back in the z-order. Then when you check that they'll just set the opacity to zero. And by "they" I mean no one. :) personally I just think it's a waste of time unless you're Doubleclick or Google. –  Josh Jun 15 '11 at 3:20
add comment

If a visitor is using say Firefox with Adblock, your banner is never going to appear in the page so mutation events won't be dispatched. You can look at the style properties and re-load the page, but it won't make the ad appear. A constantly re-loading page will annoy users so they'll leave.

If you're OK with that, go for it. Otherwise, realise that anyone disabling your ad was never going to respond to it anyway so what's the point?

share|improve this answer
Thanks @RobG, I didn't even think of Adblock, you're right in that mutation events will not work in that case. As far as disabling the ad, the point is not that I want them to click on it, the point is that there is no motivation for them to get the paid version of my app if getting rid of the ad is easier than putting their credit card info in. –  Alexander Tsepkov Jun 15 '11 at 19:07
add comment

Your Answer


