6

I've been working on something to block ads (or rather hide them) utilizing plain javascript. For ads specific to a website using something like this:

document.querySelector("img[src*='domain.com/path/to/ad/']").style.display="none" 

Actually works to find the specific image and hide it. However, google seems to be inserting their ads in an iframe that contains it's own document with a header/body/footer. It looks like this:

google ads

I haven't been able to find a way to select the adsense ad and do something with it. How would you go about selecting anything within that block?

3
  • So you're just asking how to select an element in an iframe? Commented Jul 13, 2014 at 5:25
  • You are welcome: developer.chrome.com/extensions/webRequest Commented Jul 13, 2014 at 5:28
  • @cookiemonster kinda. I am seeing about removing ads after they've loaded on iOS. Apple doesn't provide a way for us to scrutinize every URL that's going to load in a browser (as far as I know). I figured using javascript to call display none on them was the next best thing. Commented Jul 14, 2014 at 11:44

1 Answer 1

1

I believe it uses a combination of things such as the url the add originates from, the size of the banner and the code for the ad within the html of the page.

I think that adblock actually keeps the ad from loading and not just hiding it.

Why are you wanting to hide the ad. Is it your webpage you placing the javascript?

Sign up to request clarification or add additional context in comments.

2 Comments

I'm seeing if I can make an extension in iOS for safari that would remove ads after the page has loaded. For iOS you are required to use apples tools if you want to make a browser which means I don't have a way to block certain URLs from loading (as far as I know).
Firefox for iOS had an ad block so I'm sure it can be done. But I believe it filters before loading the page so I'm not sure trying to hide elements of the page will work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.