Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   Script in iframe unintentionally halting script in parent (http://www.velocityreviews.com/forums/t924614-script-in-iframe-unintentionally-halting-script-in-parent.html)

Penguiniator 05-06-2006 05:02 PM

Script in iframe unintentionally halting script in parent
 
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>


Dr John Stockton 05-06-2006 07:31 PM

Re: Script in iframe unintentionally halting script in parent
 
JRS: In article <PE47g.13815$TK1.12832@fed1read06>, dated Sat, 6 May
2006 10:02:39 remote, seen in news:comp.lang.javascript, Penguiniator
<no-spam@spamme.com> posted :

> 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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

ASM 05-07-2006 12:04 AM

Re: Script in iframe unintentionally halting script in parent
 
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 ?


> My code:


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>


<script type="text/javascript">

> 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";';
};



--
Stephane Moriaux et son [moins] vieux Mac


All times are GMT. The time now is 06:42 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.