Script in iframe unintentionally halting script in parent

P

Penguiniator

I have a script that writes the body tag and adds a background
image to its containing page. This page is displayed in an
iframe inside a td tag of a table constructed with javascript.

The table row it appears in is mid-way down the table. When the
script executes in the iframe it halts the parent window's
script, casusing the table to stop rendering after the row
containing the iframe.

I have no control over the code of the parent window.

Is this behavior normal for javascript? Is there anything I can
do with my code to compensate for the behavior of code in the
parent window?

My code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
</head>
<script>
var backgr2="images/banner2.gif"
var backgr3="images/banner3.gif"
var backgr4="images/banner4.gif"
var backgr5="images/banner5.gif"
var backgr6="images/banner6.gif"
var backgr7="images/banner7.gif"
var cur=Math.round(7*Math.random())

if (cur<=2)
backgr=backgr2
else if (cur<=3)
backgr=backgr3
else if (cur<=4)
backgr=backgr4
else if (cur<=5)
backgr=backgr5
else if (cur<=6)
backgr=backgr6
else
backgr=backgr7
document.write('<body background="'+backgr+'"
bgcolor="#000000"></body>')
</script>
</html>
 
D

Dr John Stockton

JRS: In article <PE47g.13815$TK1.12832@fed1read06>, dated Sat, 6 May
2006 10:02:39 remote, seen in Penguiniator
var backgr2="images/banner2.gif"
var backgr3="images/banner3.gif"
var backgr4="images/banner4.gif"
var backgr5="images/banner5.gif"
var backgr6="images/banner6.gif"
var backgr7="images/banner7.gif"
var cur=Math.round(7*Math.random())

if (cur<=2)
backgr=backgr2
else if (cur<=3)
backgr=backgr3
else if (cur<=4)
backgr=backgr4
else if (cur<=5)
backgr=backgr5
else if (cur<=6)
backgr=backgr6
else
backgr=backgr7


backgr = "images.banner" + Math.floor(1+Math.random()*6) + ".gif"

will do what I suppose you intended there.

Read the newsgroup FAQ, via sig line 2, particularly S 2.3 & S 4.22.

Don't let your posting agent line-wrap your code.
 
A

ASM

Penguiniator a écrit :
I have a script that writes the body tag and adds a background
image to its containing page. This page is displayed in an
iframe inside a td tag of a table constructed with javascript.

Why not to do more complicated ?
Is it an exercise ?
or do you like too much to slide on your iceberg ?


is it the code of file in your iframe ?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

Why xmlns ?
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
</head>
<script>

var backgr2="images/banner2.gif"

var backgr2="images/banner2.gif";
var backgr3="images/banner3.gif"
var backgr4="images/banner4.gif"
var backgr5="images/banner5.gif"
var backgr6="images/banner6.gif"
var backgr7="images/banner7.gif"
var cur=Math.round(7*Math.random())

if (cur<=2)
backgr=backgr2
else if (cur<=3)
backgr=backgr3
else if (cur<=4)
backgr=backgr4
else if (cur<=5)
backgr=backgr5
else if (cur<=6)
backgr=backgr6
else
backgr=backgr7
document.write('<body background="'+backgr+'"
bgcolor="#000000"></body>')

onload = function() {
width (self.document)
{
open();
write('<body background="'+backgr+
'" bgcolor="#000000"><\/body>');
close();
}
};
</script>
</html>


if that doesn't work, try :

onload = function() {
document.body.style.background = "url('+ backgr +
') repeat top left #000000";';
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top