Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with interval2

Status
Not open for further replies.

Atvr1d3r

Programmer
Nov 19, 2008
10
US
Here is my problem. For example lets say you have the following code in the body of an asp page..


<form id="form1" runat="server">
<table style="width: 100%; height: 493px; vertical-align:top" align="left">
<tr>
<td id="Col1"><iframe id="IF1" style="width:100%; height:100%"></iframe></td>
<td id="Col2"></td>
</tr>
</table>
<input type="button" value="Unload iframe 2" onclick="UnloadPage2();"/>
<script type="text/javascript" language="javascript">

var c2 = document.getElementById('Col2');
var if2 = document.createElement("iframe");
if2.style.width = 200;
if2.style.height = 100;
if2.id = 'IF2';
c2.appendChild(if2);

var if_1 = document.getElementById('IF1');
var if_2 = document.getElementById('IF2');
if_1.src = "HTML1.htm";
if_2.src = "HTML2.htm";

function UnloadPage2()
{
var i2 = document.getElementById('Col2');

i2.removeChild(i2.lastChild);

}

HTML2.htm contains the following code in the body..

<p>This is the one that causes the message box</p>
<script type="text/javascript" language="javascript">

var mytest = setInterval(test_sayHi,5000);
function test_sayHi()
{
alert('Hello world');
}
</script>

The question is why does the interval keep elapsing even after I remove the iframe with the button click on the main asp page.






 
Have you tried explicitly removing the iframe instead of assuming the lastChild is the iframe? Something like this:

Code:
var i2 = document.getElementById('IF2');
i2.parentNode.removeChild(i2);

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
I have tried removing the iframe explicitly. It still does the same thing

 
[0] There is something more to this behaviour. It attaches to ie only. This handling below cross-browser (meaning without provoking error for moz even though it doesn't do anything.)

[1] Add this global variable to the parent.
[tt]
//...etc etc
if_2.src = "HTML2.htm";
[red]var gwhdl=document.getElementById("IF2").contentWindow;[/red]
//etc etc...
[/tt]
[2] In the unloadPage2 function, add this.
[tt]
function UnloadPage2()
{
var i2 = document.getElementById('Col2');
i2.removeChild(i2.lastChild);
[blue]/* or with more focus
var if2=document.getElementById("IF2");
if2.parentNode.removeChild(if2);
*/[/blue]
[red]//now add this
gwhdl.clearInterval(gwhdl.mytest);[/red]
}
[/tt]
[3] I would say bravo to the question which bring up this feature rarely noticed.
 
Ok now here is the real problem. I'm trying to do this from the page that is loaded into the iframe instead of stopping the interval at the parent page level. I'm doing this because i'm writing pages that are being put into a pre-determined company intranet framework. Meaning the Iframes are being created and deleted from that framework and I cannot modify that code. Is there a way to do it from the Iframe page level instead of the parent level.
 
This looks like it's a browser specific problem that we are going to have to make changes to the frame work to fix.

Thanks For the advice
 
Ok now here is the real problem.

Why couldn't you have told us this to start with instead of stringing us along with a made-up example?





Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top