Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2004
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Javascript and date-specific content?

    Hello,

    I am trying to put together a website that will feature a "on this day in history" feature. I currently have 730 text files (one for each day of the year, in both french and english) that are pulled up by a Java applet and displayed according to the date the user visits the site. The problem is that I would like to be able to accomplish this using Javascript instead of the applet, which is difficult to format to look good!

    Is there a way to do this without any CGI stuff? I don't have access to the server, so it all has to be client-side.

    I should mention that I am a relative newbie to Javascript, but I'm quick to figure it out.

  • #2
    New Coder
    Join Date
    Mar 2004
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how are you accomplishing this in the Java applet? Are the text files named by the date...are you calculating some factor based on date or does it matter as long as their is one per day?

    -Simon

  • #3
    New Coder
    Join Date
    Mar 2004
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unfortunately I don't know exactly how the Applet works...I've just started working here and don't have access to a lot of things. But yes, each "this day in history" item is housed in a separate .txt file, named as 0608.txt, etc.

  • #4
    New Coder
    Join Date
    Mar 2004
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unfortunately, javascript can't read or write text files. You could do it using an activeX control. However, this is only IE and if the client has ActiveX controls enabled. Does your server support any server side scripting like PHP or Coldfusion?

    Cheers,
    Simon

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Use this script to get the content of the text file
    Code:
    <head>
    <style type="text/css">
    .history {
        font:normal 12px Arial;
    }
    </style>
    <script type="text/javascript">
    function displayHistory(){
        //generate path from today's date
        var today = new Date();
        var mm = today.getMonth()+1;
        if (mm<10) mm="0"+mm;
        var dd = today.getDate();
        if (dd<10) dd="0"+dd;
        var path = ""+mm+dd+".txt"; //this means that the txt file is in the same folder as this html file, add subdirectory (if any) or put the absolute path
        //get content of txt file
        var content = getFile(path);
        if (content){
            var histDiv = document.getElementById('hist');
            histDiv.innerHTML += '<p><pre class="history">' + historyItem + '</pre></p>';
            histDiv.style.display = "block";
        }
    }
    window.onload = displayHistory; //combine onload if you have an existing onload handler
    </script>
    </head>
    <body>
    ...
    <div id="hist" style="display:none">
    <h2>This day in history</h2>
    </div>
    <noscript>
    You missed the "This day in history" section.
    Please enable javascript or use a javascript-capable browser to see it.
    </noscript>
    ...
    Don't forget to add the script I referred above.
    Last edited by glenngv; 06-09-2004 at 07:08 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •