Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | DHTML | Q1001 [ previous next ]

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

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.