PDA

View Full Version : text file driven javascript


adfunk
02-15-2003, 11:26 AM
hie all

i would like to ask some question

how can i create a text file driven javascript? it is functioning like this

the javascript will be place in my homepage and act as a transporter for the text file that I will be place/upload on the server root

example:

html page A contain javascript X . Javascript X will read and display content in the text file F .


so it is easy in the future to change content

every time there is new content to place ... I will only have to upload the new text file F

so there is no need to access the html file ... editing the javascript and all and it is a fussy work

anyone understand what I'm requiring? it is simple and I even can't find it anywhere on major javascript search engine

plz help . thank you

redhead
02-15-2003, 11:36 AM
well... it cant be done with javascript. however... there are some alternatives you could try..

you could use an external javascript to write to more than one page... like this... and save it as a *.js file:var code = "some text <b>Perhaps some HTML in here too</b>";
code += "A little more text...";
code += "Some more... and some more... etc etc etc";

document.writeln(code);and call that into your pages like this: <script src="FILENAMEHERE.js" type="text/javascript"></script>

and that'll print whatever you want onto however many page you want it to be on...

or you could use iframes... then if you had say a menu that was on every page of your site but you didnt want to have to change and upload it on every page... you would just have to change it on one

you'd just make an html page with your menu on... say menu.html... and put it in an iframe on the pages you want it in...

<iframe src="menu.html" width="250" height="100%">
&nbsp;&nbsp;Your browser doesnt support iframes...
</iframe>

like that

hope thats given you some alternatives... any problems?:thumbsup:

whammy
02-15-2003, 12:49 PM
Also, server-side languages can read text files quite easily (but not using javascript)... for instance if your server supported ASP:

http://www.w3schools.com/asp/asp_ref_filesystem.asp

brothercake
02-16-2003, 04:55 AM
Or you could use XML instead of a text file, which can be read/processed both client-side and server-side, by CSS, javascript, PHP, ASP, Oracle, JSP, Python ....

whammy
02-16-2003, 05:22 AM
Good call...

http://www.w3schools.com/xml

...not a bad starting point... you forgot to mention .NET which also serves up Web Services in XML fairly easily... ;)

GoHF
02-17-2003, 01:52 PM
<html>
<script>
function loadTextFile(){
var textFileContent;
textFileContent = window.frames.myFrame.document.body.innerText;
// alert(textFileContent);
return textFileContent;
}
</script>

<body onload=loadTextFile()>
<iframe src=textFileWhatever.txt name="myFrame" style="display:none"></iframe>
</body>

</html>


Uncomment the "alert(textFileContent)" line (just remove the // ), and you will see the content of the text file pop up =).

This should work on IE4+, I think. Still, it would be wise to test this, as I only have 5.5 available. No other browsers will have this working, to the best of my knowledge...

brothercake
03-05-2003, 02:52 PM
Originally posted by GoHF
This should work on IE4+, I think. Still, it would be wise to test this, as I only have 5.5 available. No other browsers will have this working, to the best of my knowledge...


It will work in IE5.5 and IE6 - but actually you're reading extraneous information - the data is in child nodes [1].

It will partially work in gecko browsers - except that the text will be split into multiple nodes every x characters (I forget how big X is)

But either way - this approach is not generally a good idea; you shouldn't rely on a text document having a DOM.