iFrame.removeNode() only hides, does not destroy the iFrame node

95 pts.
Tags:
HTML Javascript
Hi,
I'm trying to remove an iFrame from my document using the removeNode() method. The iFrame seems to disappear, but remains active in teh background somewhere. I notice this when I have a script running in the iFrame that does an alert every second:
test.html
<HTML>
<HEAD>
<script language="javascript">
function closeIFrame(){
document.getElementById('myIFrame').removeNode(true)
}
</SCRIPT>
</HEAD>
<BODY>
<button onclick="closeIFrame()">close</button>
<IFRAME ID="myIFrame" src="test2.html"></IFRAME>
</BODY>
</HTML>
test2.html
<HTML>
<HEAD>
<script language="javascript">
function msg(){
alert('a message')
}
window.setInterval(msg,1000)
</SCRIPT>
</HEAD>
<BODY>
test2
</BODY>
</HTML>
So where does this iFrame go, and how to I completely destroy it?


Software/Hardware used:
HTML Javascript
ASKED: November 29, 2011  4:05 PM
UPDATED: March 6, 2012  7:03 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    To get some possible insight into what is happening, try changing this:
    window.setInterval(msg,1000)
    to this:
    window.setInterval(msg,30000)
    Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    If you tried a longer delay, you might have had some time to try a little debugging before getting multiple alerts stacking up. Ideally, you are also trying in at least FireFox and Internet Explorer and have seen that they don't quite always react the same way. (You might also try Chrome, etc., as well as different versions of browsers.) Now try changing this:
          document.getElementById('myIFrame').removeNode(true)
    to this:
          document.getElementById('myIFrame').parentNode.removeChild(document.getElementById('myIFrame'));
    And be sure to try both FF and IE (at least). That ought to be closer, but not totally there. Tom
    125,585 pointsBadges:
    report
  • Palloquin
    Hi Tom, Thank you for your insights! Please excuse my 'single browser' code... I'm building for an internal project that only runs on IE... (no excuse, I know). I noticed it might have something to do with stacking atleast. changing the interval does change something... What I found to be a working solution is to first clear the source of the iFrame before removing it:
    myIframe.src = ""
    myIframe.removeNode(true)
    
    Thank you!
    95 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following