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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

iframe inside iframe endless loading in Firefox

Status
Not open for further replies.

bokula

Programmer
May 18, 2007
5
0
0
SK
Hi all!

I have 2 pages. First page:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<title>first page</title>
</head>
<body>
<iframe src="second_page.htm" frameborder="1" width="500" height="500" id="ifrm" name="ifrm"></iframe>
</body>
</html>
And second page which is a src of iframe on first page:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<title>second page</title>
<script type="text/javascript">
function ifrm2(){
	var newIfrm = document.createElement('iframe');
	newIfrm.src = "about:blank";
	newIfrm.id = 'ifrm22';
	newIfrm.name = 'ifrm22';
	newIfrm.style.width = '250px';
	newIfrm.style.height = '250px';
	newIfrm.frameBorder = '1';
	newIfrm.onload = function(){alert(1)}
	document.body.appendChild(newIfrm);
}
window.onload=ifrm2;
</script>
</head>
<body>
</body>
</html>

Now the problem is that in Firefox the loading of first page never ends... IE and Opera doesn't have this problem. Probably the problem is in a dom iframe on second page but I can't figure it out why. Does somebody have a solution for this?

Thanks

Bokula
 
I found a solution. The problem was in loading pages. So first the First page should be loaded and then the function on Second page executed. So the solution was to put on a First page
Code:
window.onload = function(){ifrm.ifrm2()}
 
[1] I view the problem slightly differently. If you script the iframe page like this.
[tt]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"<html>
<head>
<title>second page</title>
<script type="text/javascript">
function ifrm2(){
var newIfrm = document.createElement('iframe');
newIfrm.src = "about:blank";
newIfrm.id = 'ifrm22';
newIfrm.name = 'ifrm22';
newIfrm.style.width = '250px';
newIfrm.style.height = '250px';
newIfrm.frameBorder = '1';
[red]//[/red]newIfrm.onload = function(){alert(1)} //ie won't alert
if (window.attachEvent) {
newIfrm.attachEvent("onload",function(){alert(1)});
} else if(window.addEventListener) {
newIfrm.addEventListener("load",function(){alert(1)},false);
}
[red]//[/red]document.body.appendChild(newIfrm);
document.getElementsByTagName("body")[0].appendChild(newIfrm);
}
//window.onload=ifrm2;
window.onload=function() { setTimeout("ifrm2()",10) }; //even proper with 2nd param extreme 0 ms.
</script>
</head>
<body>
</body>
</html>
[/tt]
[2] In the original, if you pay special attention on the onload, ie won't alert(1). The event attaching actually failed.

[3] In moz/ff, a simple making of a new process thread on global context would do the job. (This kind of making a branch out global context often turn up a needed way... I won't say moz/ff threading model has any delicate problem, I can't say without detail.)

[4] Your solution script parent calling child frame's function make the page dependency less clear-cut separated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top