www.webdeveloper.com
Results 1 to 5 of 5

Thread: settimeout.. strange

  1. #1
    Join Date
    Jul 2006
    Posts
    16

    settimeout.. strange

    Hello, this is what happens, I will put the problem the simplest way I can

    <script type="text/javascript">
    /* drawing lines and other stuff*/
    my_function();
    function my_function(){
    document.write("hello");
    }
    </script>

    This work fine, hello is written over everything I draw before

    Now I replace
    <script type="text/javascript">
    /* drawing lines and other stuff*/
    setTimeout("my_function()",1000);
    function my_function(){
    document.write("hello");
    }
    </script>

    On this case everything disapears and hello is written over a blank page

    the question is:
    WHY??????
    I need to fix that somehow

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,644
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    </head>
    
    <body onload="my_function();">
    <div id="fred" style="width:400px;height:100px;border:solid black 1px;">
    </div>
    <script type="text/javascript">
    /* drawing lines and other stuff*/
    function my_function(){
    document.getElementById('fred').innerHTML+=document.getElementById('fred').innerHTML+'document.write can only be used when the page is first rendered<br>';
    setTimeout("my_function()",1000);
    }
    </script>
    
    </html>
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. #3
    Join Date
    Jul 2006
    Posts
    16
    well, I was looking for a generic solution, since my objective is not to do a document.write, but to update graphics every second using a graphic library

    <body> <script type="text/javascript" src="wz_jsgraphics.js"></script> </body>

    instead of document.write("hello") , I want to do
    line();

    where:

    function line()
    {
    jg_doc.setColor("#ff0000"); // red
    jg_doc.drawLine(10, 113, 220, 55); //
    jg_doc.paint();
    }

  4. #4
    Join Date
    Mar 2005
    Posts
    767
    RTFM: http://www.walterzorn.com/jsgraphics...ics_e.htm#docu "Draw into DIV elements even after the page has fully loaded"
    Stop thinking, start drinking.

  5. #5
    Join Date
    Jul 2006
    Posts
    16
    Quote Originally Posted by Orc Scorcher
    RTFM: http://www.walterzorn.com/jsgraphics...ics_e.htm#docu "Draw into DIV elements even after the page has fully loaded"
    Yep, it is well explained there.. I am a fool, i didn't read it carefully.. thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles