5

I'm currently using Chrome 27.

After looking through the settings options (Settings → Privacy → Content settings) I see that I can disable just about anything... except iframes.

Is there any easy way to do this? Is it also possible in IE and Firefox?

gronostaj
  • 55,965
  • 20
  • 120
  • 179
Danield
  • 393
  • 3
  • 6
  • 14

2 Answers2

3

I ended up using the extension "stylish"

It lets you target particular urls and then you can add custom styles for that website.

Here's a post in Stack overflow which illustrates this.

So in my case I added the following custom css for the particular website i needed to target

iframe
{
  display: none;
}

... and it works great!

Danield
  • 393
  • 3
  • 6
  • 14
  • 4
    What’s the point in doing this? The javascript in iframes will still execute. – kinokijuf Jun 17 '13 at 08:39
  • 5
    As i mentioned in the comments on the question, I just want to hide the content of the iframes on a particular website. It's not a security concern here – Danield Jun 17 '13 at 08:42
  • 1
    There’s no point in doing this – kinokijuf Jun 17 '13 at 08:47
  • 4
    It is indeed useful for hiding the iframe. Thanks for the solution. – acsadam0404 Apr 23 '14 at 08:08
  • 3
    The point is, when an ugly iframe is overlapping the main content on a poorly designed website. Don't question the usefulness, just that there's one person who needs it! – Vijay Nov 07 '14 at 07:18
2

Just remove all elements that are iframes with javascript directly in the console

or install a plugin for a more permanent solution like: noscript

Temporary fix

One Line:

(function(){var f=document.getElementsByTagName("iframe");for(var i in f)try{f[i].parentNode.removeChild(f[i]);}catch(e){console.error(e);}})();

This will permanently remove the iframes on page. (until the page is refreshed)

To use this live

  • open console (F12 key)
  • navigate to the console tab
  • paste the one line or the human code into the

    >
    

    field and press Enter

Human code:

(function(){
var listOfFrames = document.getElementsByTagName("iframe");

while (listOfFrames /*exists*/ && (listOfFrames.length > 0) ) {
  try {
    for (var iterator in listOfFrames) {
      listOfFrames[iterator]                  // get the next frame
      .parentNode                             // find the parent 
      .removeChild( listOfFrames[iterator] ); // remove the frame from the parent
    }
  }catch(e){                                  // we found a frame that no longer exists
    console.error(e);
  }
  var listOfFrames = 
     document.getElementsByTagName("iframe"); // update the list regardless of errors in case we missed one
}                                             // loop again unless the condition is satisfied
})();                                         // end of call of the function

Before you try this

If you don't know your browser's behavior around loops and removing elements make sure everything is saved locally or on the server before you start. Running the code might remove your work. Be sure that you will be okay if your browser crashes.

I edited this because I didn't think it was readable hopefully it's better.

haelmic
  • 143
  • 5
  • Minor note: I'd expect the `try...catch` around the `f[i] .parentNode .removeChild(f[i])` to ensure others are still deleted. – Arjan Jun 05 '17 at 05:12
  • Thanks for you're input @Arjan I'll add a tweak that works a bit better, to my answer. – haelmic Jun 06 '17 at 01:50
  • Won't this lead to an infinite loop if removing one of the iframes fails (and keeps failing)? – Venryx Dec 06 '18 at 22:08
  • @Venryx It might be possible... the need for the try catch was from iframes that were nested and therefore already deleted. I don't know if `removeChild` can fail any other way. If it can then there would be an event queue feedback. As I don't think removeChild can fail any other way, I don't think it can happen. – haelmic Dec 24 '18 at 03:29