4

I would like to hide elements which have a specific attribute inside an iframe. For example, I want to hide all elements with attribute load-ads-json-from, and there is an element <div load-ads-json-from='//ad.server.net/some/resource'> inside an iframe <iframe src="https://content.server.net/where/the/content/is">.

So far I've tried ##iframe > [load-ads-json-from], or simply ##[load-ads-json-from]. Both don't work. I can conditionally hide the <iframe /> entirely, based on its src attribute, but there is useful info in the page that should not be hidden altogether.

Is there a way to do this?

1
  • You cannot select elements across frame boundaries so ##iframe > [load-ads-json-from] isn't expected to work. However, ##[load-ads-json-from] should work. You can try to open the frame in a new tab to make it easier to debug or, in case you're using Adblock Plus, you can find which filters the extension applies using its panel in the browser's developer tools. Because it could be that a different filter interfers with this filter (e.g. by whitelisting the frame's content or disabling hiding rules for that particular domain).
    – greiner
    Commented Jun 7, 2019 at 13:33

1 Answer 1

3

Here is one way to block elements within an iframe:

  1. open developer tools:
  2. click on "Inspect" or "Select element", usually it's an icon of a mouse cursor above a rectangle, like so (Firefox): mouse cursor above a rectangle;
  3. select the iframe, you'll see something like this: iframe element with attributes;
    • if you happen to click an element within the iframe, don't worry, scroll up in devtools until you see the <iframe> element;
  4. right-click on the "src" attribute value (the URL) to bring up the context menu of your browser;
  5. copy or open the URL in another tab;
  6. filter whatever you have to filter;
  7. close the tab;
  8. refresh the original or all tab(s);

there you go, you have successfully blocked an element within the iframe.

It's easier if you already have the original URL of the iframe, just open in another tab and set your filter.

It works for uBlock Origin.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .