Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1001 How do I write text slowly across the screen using a character string stored in a varable?

You are here: irt.org | FAQ | DHTML | Q1001 [ previous next ]

Normally, if you write text to the document after the document has finished loading then the new text will totally replace the whole document - losing your document, JavaScript, variables, data and client state.

Generally you would be better writing to another frame or another window.

However, it is possible in Internet Explorer 3+ to write to a floating frame within the document, and it is possible in Internet Explorer 4+ and Netscape Navigator 4+ to use DHTML and write into "layers":

<SCRIPT LANGUAGE="JavaScript"><!--
var input = 'abcdefghijklmnopqrstuvwxyz';
var output = '';
var count = 0;

function update() {
    if (document.all)
        document.all.myDiv.innerHTML = output;
    else if (document.layers) {
        document.layers['myLayer'].document.open();
        document.layers['myLayer'].document.write(output);
        document.layers['myLayer'].document.close();
    }
    else if (frames.length != 0) {
        window.frames[0].document.open();
        window.frames[0].document.write(output);
        window.frames[0].document.close();
    }
}

function tickerTape() {
    output = input.substring(0,++count);
    update();
    if (output.length < input.length)
        setTimeout('tickerTape()',100);
}
//--></SCRIPT>

<BODY onLoad="if (document.all || document.layers || frames.length != 0) tickerTape()">

<DIV ID="myDiv"><LAYER ID="myLayer"></LAYER></DIV>

<SCRIPT LANGUAGE="JavaScript"><!--
if (!(document.all || document.layers)) {
    document.write('<IFRAME NAME="myFrame"></IFRAME>');
}
//--></SCRIPT>

©2018 Martin Webb