JSFiddle - React, Tailwind, and code Playground

by davidmurdoch

HTML

<p>Clicking "Leak" will load an image-search results page in an iframe. As soon as the iframe's load event is fired the iframe is removed using jquery's <code>remove()</code> method and then a new iframe is created and appended to the containing element with a new search phrase.</p>
<p>
    Open Chrome's task manager (Shift+Esc), or your prefered memory analysis tool, and watch the memory use climb.
</p>
<button>Leak</button>
<div>Hello, I'm the containing element.</div>

CSS

body{
    font-family:sans-serif;
    font-size:12px;
}
p{
 margin:10px;   
}
iframe{
    width:100%;
    height:300px;
    display:block; 
}

JavaScript

var leak = false,
    containerDiv = $("div"),
    iframe = null,
    url = "http://www.google.com/images?q=";

containerDiv.empty();

$("button").click(function(e){
    e.preventDefault();
    
    // remove the iframe and empty the container
    iframe && iframe.remove();
    containerDiv.empty();
    
    if(leak){
        leak = false;
        
        iframe = null;
        
        this.innerHTML = "Leak";
    }
    else{
        leak = true;
        
        // create a new iframe and add it to the DOM
        iframe = createIframe();
        iframe.attr("src", url + "i will be leaking now");
        iframe.appendTo(containerDiv);
        
        this.innerHTML = "Stop";
    }
});


// Creates a new iframe and sets its load event
function createIframe(){
    var iframe = $("<iframe security=restricted></iframe>");
    iframe.load(function(){
        if(leak){
            var term = getRandomSearchTerm();
            $(this).attr("src", url + term);
        }
    });
    return iframe;
}

// you really shouldn't care about this...
function getRandomSearchTerm(){
    var names = "Justin Bieber,Lady Gaga,Kim Kardashian,Rihanna,Jordan,Miley Cyrus,Britney Spears,Lindsay Lohan,Jessica Alba,Katy Perry,Selena Gomez,Rachel Bilson,Kelly Osbourne,Vanessa Hudgens,Natalie Portman,Fergie,Emma Watson,Avril Lavigne,Halle Berry,Eva Longoria,Nicole Kidman,Russell Brand,Ed Westwick,Hilary Duff,Scarlett Johansson,Jonas Akerlund,Leighton Meester,Dianna Agron,Gwen Stefani,Blake Lively,Paris Hilton,Fearne Cotton,Selma Blair,Nicole Richie,Christina Aguilera,Kourtney Kardashian,Claudia Schiffer,Gabriel Aubry,Zoe Saldana,Doda,Nicky Hilton,Jennifer Hudson,Jennifer Lopez,Nicki Minaj,Jennifer Aniston,Cheryl Cole,Nick Jonas,Kate Moss,Cash Warren,Whitney Port,Keira Knightley,Vivienne Westwood,Kate Hudson,Pete Wentz,Jake Gyllenhaal,Diane Kruger,Kat Von D,Adam Lambert ,Milla Jovovich,Anne Hathaway,Amanda Bynes,Toni Braxton,Taylor Swift,Tony Parker,Helena Bonham Carter,Jenna...