Coding Cookbook/Statusbar Ticker

From Wikibooks, open books for an open world
Jump to: navigation, search

JavaScript solution[edit]

<script>
var init_msg = "This text will be repeatedly build up on the statusbar.               "

var str = ""
var msg = ""
var leftmsg = ""

function setMessage() {
        if (msg == "") {
                str = " "
                msg = init_msg
                leftmsg = ""
        }
        if (str.length == 1) {
                while (msg.substring(0, 1) == " ") {
                        leftmsg = leftmsg + str
                        str = msg.substring(0, 1)
                        msg = msg.substring(1, msg.length)
                }
                leftmsg = leftmsg + str
                str = msg.substring(0, 1)
                msg = msg.substring(1, msg.length)
                for (var ii = 0; ii < 120; ii++)
                        {str = " " + str}
        }
        else { 
                str = str.substring(10, str.length)
        }
        window.status = leftmsg + str
        window.setTimeout('setMessage()',10)
}
</script>

<body OnLoad="window.setTimeout('setMessage()',800);"></body>