Script in iframe unintentionally halting script in parent

Discussion in 'Javascript' started by Penguiniator, May 6, 2006.

  1. Penguiniator

    Penguiniator Guest

    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>
     
    Penguiniator, May 6, 2006
    #1
    1. Advertising

  2. JRS: In article <PE47g.13815$TK1.12832@fed1read06>, dated Sat, 6 May
    2006 10:02:39 remote, seen in news:comp.lang.javascript, Penguiniator
    <> 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.
     
    Dr John Stockton, May 6, 2006
    #2
    1. Advertising

  3. Penguiniator

    ASM Guest

    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
     
    ASM, May 7, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DMS
    Replies:
    0
    Views:
    331
  2. dushkin
    Replies:
    0
    Views:
    369
    dushkin
    Apr 23, 2006
  3. Markus
    Replies:
    0
    Views:
    391
    Markus
    Feb 9, 2005
  4. Markus
    Replies:
    0
    Views:
    381
    Markus
    Feb 9, 2005
  5. Markus
    Replies:
    1
    Views:
    448
    Richard Tobin
    Feb 9, 2005
Loading...

Share This Page