User Tools

Site Tools


Sidebar


Site Information


Interactive Maps

Sidebar

scode:js:rdfile

Read File

Yes. You can read a file. In JavaScript.

I had a couple buttons at the bottom of a page you could click to get different topics, and I'd display the contents in a div (called "helptext") at the very bottom.

function dynoHtml(x) {
    var oHelpTxt = document.getElementById('helptext');
    var sIncDir = './includes/';
    var sFileName;
 
    if ('about' == x) {
        sFileName = sIncDir + 'about.html';
    } else if ('help' == x){
        sFileName = sIncDir + 'help2.html';
    } else if ('index' == x){
        alert("Howdy");
        window.location.href = 'index2.shtml';
    } else {
        oHelpTxt.innerHTML = '';
    }
 
    var rawFile = new XMLHttpRequest();
    // using the "+ '?_=' + new Date().getTime()" to generate a 
    // "new URI" (almost) everytime to prevent caching...
    rawFile.open("GET", sFileName + '?_=' + new Date().getTime(), true);
    rawFile.onreadystatechange = function ()
    {
        if(rawFile.readyState === 4)
        {
            if(rawFile.status === 200 || rawFile.status == 0)
            {
                var allText = rawFile.responseText;
                oHelpTxt.innerHTML = allText;
            }
        }
    }
    rawFile.send(null);
 
}
scode/js/rdfile.txt · Last modified: 2017/12/19 04:25 by terrill