Append to a webpage in javascript
        Posted  
        
            by Lily
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Lily
        
        
        
        Published on 2010-04-28T22:33:06Z
        Indexed on 
            2010/04/28
            22:37 UTC
        
        
        Read the original article
        Hit count: 382
        
What I want to do is that: a webpage with continuously updating content. (In my case is updating every 2s) New content is appended to the old one instead of overwriting the old one.
Here is the code I have:
var msg_list = new Array(
    "<message>Hello, Clare</message>", "<message>Hello,Lily</message>",
    "<message>Hello, Kevin</message>", "<message>Hello, Bill</message>"
);
var number = 0;
function send_msg()
{
    document.write(number + " " + msg_list[number%4]+'<br/>');
    number = number + 1;
}
var my_interval = setInterval('send_msg()', 2000); 
However, in both IE and Firefox, only one line is printed out, and the page will not be updated anymore. Interestingly in Chrome, the lines being printed out continuously, which is what I am looking for.
I know that document.write() is called when the page is loaded according to this. So it's definitely not the way to update the webpage continuously. What will be the best way to achieve what I want to do?
Totally newbie in Javascript. Thank you.
Lily
© Stack Overflow or respective owner