Using the following example:
domiframetest.h tml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>DOM Iframe Test</title>
<script type="text/javascript">
function createIframe(){
var Iframe = document.create Element('iframe ');
Iframe.id = 'DOMIframe';
Iframe.name = 'DOMIframe';
Iframe.src = 'functiontest.h tml';
Iframe.style.he ight = '60px';
Iframe.style.wi dth = '200px';
Iframe.style.bo rder = '1px solid #ff0000';
document.body.a ppendChild(Ifra me);
}
function destroyIframe() {
document.body.r emoveChild(docu ment.getElement ById('DOMIframe '));
}
function testIframeFunct ion(){
window.frames['DOMIframe'].doAlert();
}
</script>
</head>
<body>
<input name="Create Iframe" type="button" value="Create Iframe"
onclick="create Iframe(); return false" /> <input name="Destroy Iframe"
type="button" value="Destroy Iframe" onclick="destro yIframe(); return
false" /> <input name="Test Iframe Function" type="button" value="Test
Iframe Function" onclick="testIf rameFunction(); return false" /><br />
</body>
</html>
[/code]
functiontest.ht ml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Functi on Test</title>
<script type="text/javascript">
function doAlert(){
alert('Function Successful');
}
</script>
</head>
<body>
<p>Function Test</p>
</body>
</html>
I seem to be having a strange problem regarding a DOM created IFRAME
and cross frame scripting.
If I create an IFRAME with DOM and then try and access a function
within the IFRAME everything works as expected. The IFRAME's doAlert()
function fires, everyone is happy.
However, if I then remove the IFRAME element and recreate it, The
IFRAME's doAlert() function DOES NOT fire producing the error
"window.frames. DOMIframe.doAle rt is not a function" and everyone is sad
:(
The really strange part is that I can initially create and remove the
IFRAME as many times as I want and the doAlert() function still fires.
As soon as I access the doAlert() function for the first time removing
/ recreating the IFRAME element will break the script.
Everything works as expected in IE, as long as the IFRAME is there, the
doAlert() function fires.
Using the same name / id for the IFRAME should be valid as my intention
is to only have one element created at a time. The Firefox DOM
inspector reports that the node is getting removed properly from the
DOM tree (so I am clearly not overlapping id's).
Which leads me to ???, my only guess is that my frame call is wrong
"window.fra mes['DOMIframe'].doAlert();" (I have tried numerous other
cross frame calls though) or Firefox has a bug that breaks that call
when your creating / removing DOM elements on the fly.
Any help would be appreciated.