Lee Loftiss
Lee Loftiss

Reputation: 3195

remove HTML from inside iframe using Javascript, not jQuery

I have an <iframe> that is added and removed from the stage as needed. Each time I add it, it needs to load a new page.

I need to get it to remove the previous contents so the frame is empty while the new page is loading.

Here is the code involved:

HTML:

<div id='overlay' class='overlay'></div> 
<div id="overlay_displayer_wrapper" class="overlay_displayer_wrapper">
    <div id='overlay_displayer' class='overlayDisplayer'>         
    <iframe id='i_displayer' class='i_displayer'></iframe>     
    </div>
</div>

This is the code that 'launches' the overlay and iframe above:

function launchDisplayer(img_src, base_directory, session_pics){
showDisplayer(true);
document.getElementById( 'i_displayer' ).setAttribute( 'src', '' );
document.getElementById("i_displayer").src="feeder.php?call=main&curr=" + img_src + "&dir=" + base_directory + "&pics=" + session_pics;
}

This is the function showDisplayer():

function showDisplayer(show){
var overlay = document.getElementById("overlay");
var overlay_displayer = document.getElementById("overlay_displayer_wrapper");
if (show){
    overlay.style.display = "block";
    overlay_displayer.style.display = "block";
}else{
    overlay.style.display = "none";
    overlay_displayer.style.display = "none";

}
}

That's all the code involved in this action.

Upvotes: 0

Views: 3789

Answers (1)

ThinkingStiff
ThinkingStiff

Reputation: 65351

Just clear the src.

Demo: http://jsfiddle.net/ThinkingStiff/9ZrMZ/

HTML:

<iframe id="myframe" src="http://thinkingstiff.com"></iframe>

Script:

document.getElementById( 'myframe' ).setAttribute( 'src', '' );

Upvotes: 1

Related Questions