Click to See Complete Forum and Search --> : how to read from a textfile


trooper42
04-10-2003, 02:38 AM
I'm trying to creat a chatroom, but my mainframe (where the messages are postet) is all the time refreshing. it's getting pretty annoying after a while. does anyone have an idea how i could show the new messages on the message board without refreshing the mainframe all the time? thanks!

i think i need to use javascript, I tryed it with PHP, but its not working.

www.ihcgreifensee.ch/chatindex.php

viravan
04-10-2003, 10:03 AM
Here is an example on how to read a text file from the server via IE and NN4+:


<HTML xmlns:msie>
<msie:download id="downloader" style="behavior:url(#default#download)" />
<HEAD>
<SCRIPT>
(document.all) ? NS=false : NS=true;
if (NS) {document.captureEvents(Event.KEYPRESS);}
document.onkeypress=keyCheck;
function keyCheck(e)
{
(NS) ? kCode=e.which : kCode=event.keyCode;
if (kCode==13) {loadFile();return false;}
return true;
}
function fetchURL(url)
{
if ((location.host == '' && url.indexOf(location.protocol)==-1) || url.indexOf(location.host)==-1)
{netscape.security.PrivilegeManager.enablePrivilege("UniversalConnect");}
var dest=new java.net.URL(url);
var dis=new java.io.DataInputStream(dest.openStream());
var res=new Array();
var i=0;
while ((line=dis.readLine())!=null) {
res[i]=String(line);
i++;
}
dis.close();
(res.length==0) ? alert(file+" is mpty or non-existent!") : alert(res);
}
function loadFile()
{
(NS) ? fileName=document.xxx.filnam.value : fileName=document.getElementById("xxx").filnam.value;
if (fileName=="") {alert("File name not specified!");return;}
if (document.all && document.getElementById) {
downloader.startDownload(fileName,displayFile);
} else {
var i=new Image();
i.src=fileName;
var fileURL=i.src;
fetchURL(fileURL);
}
}
function displayFile (text) {
(text.length==0) ? alert(file+" is empty or non-existent!") : alert(text);
}
</SCRIPT>
</HEAD>
<BODY>
Enter name of text file to list (e.g., nocache.txt)
<form name="xxx"><input type="text" name="filnam" value="nocache.txt" size=50>
</form>
<script>
(NS) ? document.xxx.filnam.focus() : document.getElementById("xxx").filnam.focus();
</script>
</BODY>
</HTML>



I wrote this a few years back and haven't touched it since, so I don't know if it still works...just check it out.


:)

V.V.