Skip to content

Instantly share code, notes, and snippets.

@rodmcnew
Last active March 2, 2022 23:07
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rodmcnew/fe5489c9e3081300444c400e6c60bbfa to your computer and use it in GitHub Desktop.
This is a bookmarklet that removes all iframes from the current page. Paste its code into a bookmark URL field. Click the bookmark to remove all iframes. Once started, it also removes newly spawned iframes every 100ms.
javascript:void(function(){setInterval(function(){document.querySelectorAll('iframe').forEach(function(element){console.log('Iframe Killa - Removing Element:', element);element.parentNode.removeChild(element)})},100)}());
@rodmcnew
Copy link
Author

rodmcnew commented Dec 2, 2019

Why show "random" number and remove all form body?

<html><head></head><body>1229</body></html>

Nothing in this code does that. All this does is delete all the iframe elements from the page every 100ms.

@krystian3w
Copy link

krystian3w commented Dec 3, 2019

So my Firefox 71 RC4 is broken...

Even if a page has an iframe, it still unloads all the content from the page (change into "random" number).

@rodmcnew
Copy link
Author

rodmcnew commented Dec 3, 2019

@krystian3w I just fixed it for Firefox. Firefox apparently likes to display the return value of the bookmarklet code. The random number was the timer ID. Happy iframe killing.

@JAffleck
Copy link

JAffleck commented Jun 4, 2020

I made it also remove script elements, so now news sites are actually pleasant to visit :)

javascript:void(function(){setInterval(function(){document.querySelectorAll('iframe,script').forEach(function(element){element.parentNode.removeChild(element)})},100)}());

@krystian3w
Copy link

krystian3w commented Jun 4, 2020

@JAffleck
Copy link

JAffleck commented Jun 4, 2020

Cool info! Thanks for sharing.

@dnmTX
Copy link

dnmTX commented May 25, 2021

Rod @rodmcnew or James @JAffleck how about just to engage one time when activating the bookmarklet instead of spawning every 100ms. ?
Can you make simpler script?
What about UserScript version,this way some websites can be excluded with @grant GM_getResourceURL and @exclude ..... ?
Great work though,keep it up 👍

@rodmcnew
Copy link
Author

@dnmTX
Here is a version that runs once only when clicked:

javascript:void(function(){document.querySelectorAll('iframe').forEach(function(element){console.log('Iframe Killa - Removing Element:', element);element.parentNode.removeChild(element)})}());

UserScript and website excludes: Could be interesting. Good luck if someone tries. Similar things may already exist somewhere.

@dnmTX
Copy link

dnmTX commented Jun 16, 2021

Rod @rodmcnew,with a slight delay i'm back to thank you. The truth is i ended up using your first creation due to stubborn websites like
amazon.com,imdb.com and whatnot respawning those f*ckers all the time 😄
The UserScript actually is coming up nicely,i'm in the final stages but banging my head here how to implement to check first if the page has any iframes at all and if not to quit altogether. For example,this is telling me if there are any or there aren't:
(function() { if (document.querySelector('iframe') == null) console.log("no iframes"); else console.log("iframes exist");}
You mind providing some assistance,anything will be greatly appreciated. If you want i can paste here what i got so far.
Either way,big THANK YOU 👍 Your code is working great 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment