...

View Full Version : Javascript and date-specific content?



OO7girl
06-08-2004, 03:05 PM
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.

sidvorak
06-08-2004, 05:09 PM
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

OO7girl
06-08-2004, 06:40 PM
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.

sidvorak
06-09-2004, 05:14 AM
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

glenngv
06-09-2004, 06:04 AM
Use this script (http://www.codingforums.com/showthread.php?t=30449) to get the content of the text file


<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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum