evolt.org
Join | Browsers | Lists | tips | Members | directory
HomeFAQContact
11/28/2001
Site development

(text)Dateien load with JavaScript

Author: janwinkler Between 1 and 5 Articles Written
Print Article

 

Who has even homepage, and this by interactive items to animate wants, came or goes certainly past once also at JavaScript. Who strives then still for higher one, as for instance a data base or such functions, comes however with JavaScript fast to its boundaries. Loading (~ reading in) of text and other files with JavaScript or JScript is already since the primeval times of the two languages a topic for itself. Since JavaScript do not have like also JScript a direct acces to the file system, must after other possibilities or cheat to be looked up. In the following now some solutions are to be given and treated for this problem.

The target consists then of it ( dynamically ) a text ( pours. * * * ) into the document ( target. * * * to merge) and to make the result for the visitor visible.

As basic stick thereby for a possibility one looks up in each case to load data into a variable . This variable is to be simply only written then into the document.

The simple Script version

One of the oldest and at the same time simplest ideas data into a variable to load consists of simply already having the data in a variable and these to loading. This way is completely sufficient and besides still very uncomplicated for most applications.

The idea is, the data, which are to be loaded later, than values of defined variables in a js - to store file and these then - if they are needed - into the HTML - file to load. For it thus 2 files are needed: We call it times quelle.js and target htm

Example:

In quelle.js :

In target htm :

The dynamic Script version

In order loading of files now still somewhat more freely to gestallten, is to be merged it e.g. possible, the respective JavaScript file dynamically. This falls back also again to the first idea, with the difference that here the entire file and not only the text from a file is merged dynamically. In the following example it is assumed that the text variable source is stored in the file quelle.js. In the file becomes as additional entry document.writeln(Quelle); at the end inserted. The pertinent HTML - file loads the file as Script. Also the code contained in it is executed by loading and thus the text is written. Thus it is to be loaded quasi possible any (vorpreparierte) files.

Example:

In quelle.js :

In target htm :

The window version

A further idea to read data in in JavaScript is the window version. The consideration consists of opening the file which can be read in into a new Browser window and selecting this then. Opening might represent thereby no larger problem. To only note it is that the file is if possible marked by file dung, which is not executed by the Browser or is not loaded down as Download. It should be thus guaranteed that the file is displayed by the Browser.
As by far the larger problem then the selection of the window presents itself. With Microsofts Internet Explorer goes this relatively simply:
The document is queried and selected by the opened window by this again with body.innerHTML or documentElement.innerHTML contents. The difference of the two is situated in the fact that with body really only contents of the Bodys are output-asked, against what document item outputs the root item of the file. For example if the text which can be read is stored into a file with the ending htm or html, then it normally gets - even if it no HTML - it contains formatting - a certain essential structure of the Browser lent (to which e.g. head or body belong). These off by only the Body being able to switch is output-asked - the queried text is however (after some transformations) the same.

Which concerns the Netscape navigator or other Browser, then is this idea fewer easily umzusetzten.
The Netscape navigator offers 6.0 no possibilities contents of an item or the document before the version to actually select. Starting from 6.0 - similarly as with the Internet Explorer - with document.documentElement.innerHTML contents of the root item can be picked out. The text with document.body.innerHTML to read in does not seem to function here however.

Opera and other Browser are to be induced against it not really to out-spit contents.

If the data are however firstonce unloaded, they must only processed and the Browser window can be closed again.

Example:

In quelle.txt :

In target htm :

A further problem thereby is that perhaps, as soon as the loading procedure of the window persists too long the Ausfragen of the window causes no results or an error. It is advisable with events to operate (e.g. onLoad ).

The ActiveX version

Beside numerous other things - which do not control other Browser - the Internet Explorer also the possibility has to access ActiveX objects. The idea is now to use easily the responsible ActiveX object FileSystemObject around a file to open to read and output the text.

Also here again a larger problem develops: If the Script is executed with the Clienten, then a file in the Internet is found and cannot not be opened therefore. In addition it comes still that 1. of the ms Internet Explorer must be used and 2. ActiveX to be switched on must.

This version is rather interesting for server-lateral inserting (e.g. with ASP ) - for application in the own Intranet (etc..) it would be to be used however also in normal Internet pages.

Example:

In quelle.txt :

In target htm :

The DATA being thing version (ActiveX Nr.2)

A further idea which is based on ActiveX is Microsofts DATA being thing or DATA-BINDS. In the Internet Explorer are used or Windows of integierte ActiveX control members. These can with the HTML - item to be object merged and through param controlled. Around data classid the ' CLSID:333C7BC4-460F-11D0-BC04-0080C705Ä83 ' will merge used. As parameters in addition the among other things following can be transferred:

  • DataURL - the file which can be opened
  • TextQualifier - separators which can be used

One is given to the object id. Within the page can then over these id div - item to be inserted, which to this object (by datascr - an attribute) refers. If it concerns with the data text, should be indicated additionally datafld " = " text. Additionally with dataformatas = HTML " " formatting the data can be defined as HTML.

The file which can be opened must additionally still (in order-)formatiert become. The first line should ' ext:String$ ' reads, whereby $ against the designated separators ( TextQualifier - attribute) to be exchanged can. Additionally each further line with this separator must be begun and terminated.

Example:

In quelle.txt :

In target htm :

The Java version

Further idea consists of accessing on Java for reading the file back. There the Netscape navigator in a the position is to be operated between Java and JavaScript communication, can here the data thus also with JavaScript further be processed. The Internet Explorer does not support this unfortunately - for it the Java code would have to be packed therefore in an applet. The file is equipped also here beforehand with separators and formatting, so that the files from the DATA Bining version can be used. The following code is suitable for selects from files with Java.

Example:

In quelle.txt :

In target htm :

Alternative one to JavaScript

The described ideas for most simple JavaScript /Homepage amateur handicraftsmen will be completely sufficient, yet no really professional solution with JavaScript or Jscript can be attained. For most users the attention will therefore be directed rather toward another language.
For it server-lateral languages are useful such as PHP or ASP . The advantage is thereby clearly obvious: Since the Client of the server gets only the results of merging, it is no matter, which for a Browser it has and it functions imme *** TRANSLATION ENDS HERE ***r. Eine mögliche PHP -Umsetzung zum Einbinden einer Textdatei wäre zum Beispiel:

In quelle.txt :

In ziel.php :

Fazit

Letztlich sollte jeder selbst sehen, was für seine Bedürfnisse am Besten und ausreichend professionell genug ist. PHP oder ASP bieten sicherlich die beste Möglichkeit, wobei - je nach Anwendung - auch einfache JavaScript-Varianten durchaus ihren Dienst tun können.

PS: Dank an Andreas Zierhut ( http://www.dhtml-now.de / http://www.dhtml-now.de/javascr/sonstiges/externedatei.asp ) .

 
 

 Rating

  This article currently has a rating of 3.33 out of 6 total ratings.  
 

Would you like to rate this article? Article ratings encourage evolt contributors to keep writing the good stuff. Help make our authors feel wanted! You need to log in to rate an article -- you can enter your username and password on the right -- and if you haven't yet done so, please register your username before logging in.

 
     
 

 Reader Comments

     
[Link]

Internet : a national world

skamp wrote on 11/29/2001 at 2:46 PM
 
I find very disappointing that some people just don't bother writing in english over the Internet (web and other). How many people do you think speak german ? Even if you don't write english well (like me), it doesn't matter, the point is to be understood by the mass...
 
[Link]
jobarr wrote on 11/29/2001 at 5:11 PM  
Or, the point is to be understood by *someone*. If you don't understand German, just ignore it.
 
[Link]
simonc wrote on 11/29/2001 at 5:46 PM  
I'm with jobarr, although I do feel like I'm missing out on what looks like a really interesting article. If a kind multi-lingual evolter could find the time for a translation I'm sure many of us would appreciate it - the BabelFish Translation doesn't make a great deal of sense, unfortunately.
 
[Link]

Thanks for the feedback

mwarden wrote on 11/29/2001 at 6:13 PM
 

This is pretty much what I was afraid was going to happen. We have an English translation, but no one but me seems to want to publish it. One admin mentioned that there may be some technical issues with supporting multiple versions of the same article in the CMS as well.

Sorry for springing this change on you without any warning (other than the synopsis). Admin could have handled this better.


 
[Link]

Good going there Germany :-=

pawd wrote on 11/30/2001 at 0:19 AM
 
Lieber jan winkler. Du bist doch ein eierkopf ! I´ve had it with German arrogance !! The rest of the world actually speaks English.
How would you feel if I posted something written in Danish in your precious German DHTML-forum ? THINK ABOUT IT !!
In Denmark we are actually forced to learn your language, but we never use it. Why ? Because we don´t live in Germany.
The International language is ENGLISH !
This is not about the war. It´s about respect for your fellow human beings.
 
[Link]

Regarding your posting

pawd wrote on 11/30/2001 at 0:28 AM
 
Though I´m probably one of the few who were able to actually READ your posting, I found it very good.
www.dhtml-now.de is pretty good too.
See you around

The Viking
 
[Link]

Hey

janwinkler wrote on 11/30/2001 at 0:36 AM
 
I wrote a letter to the evolt team and asked if it is possible to write in german 'cause writing in english could be difficult. The team said that it would be ok and so i wrote in german. if you couldn't read this article because you don't speak german, just let it be and look at the other nice articles here on evolt. and if you want to have an international site then respect others to write in their language. jan.
 
[Link]

Sad

skamp wrote on 11/30/2001 at 6:46 AM
 
Ok, how about writing articles in French ? Here we go : I write mine in french, you write yours in german, pawd writes his in danish... Do you really think that's interesting ? This site is about sharing ideas, experiences. How the hell do you expect sharing whatsoever by writing in german ?
 
[Link]

Publishing in multiple language

MartinB wrote on 11/30/2001 at 10:04 AM
 

In response to the above points:

  1. Who reads German? Everyone in Germany (and Austria and a fair chunk of Swizerland). This is a global community, not an American one. It's as appropriate to demand that all content be in English as to demand that it all be in German. It's all good - or it's incredibly egocentric. (American) English is not the international language. It's a national language which many people have as a second language - it's perfectly OK that members of the community want to publish in their first one.
  2. The translation we have is a slightly tidied Babelfish one. It was never suggested that that poor translation be posted and I'm sorry that a misunderstanding arose over it. If anyone else feels sufficiently motivated to idiomatically translate into English, Fran ç ais , Dansk, Espa ñ ol and add the translation as a comment, please feel free. No-one suggested not doing that. If you feel that the Babelfish translation is good enough, post that.
  3. I'm sorry if anyone felt that having some content not in their own first language was springing something on them. But of course our members whose first language is not English have had this for some time - publishing one article in another language can hardly be arrogance.
  4. You want to write in French? Rock on. Same for Danish. Same for Icelandic. It might not go up until it can be reviewed (which may require translation), but it's all good.
  5. By writing in German, it shares with everyone who can read German. This is an improvement on "The article isn't written ".

 
[Link]

Re: Publishing in multiple language

mwarden wrote on 11/30/2001 at 4:35 PM
 

martinb wrote: By writing in German, it shares with everyone who can read German. This is an improvement on "The article isn't written".

Sure isn't an improvement on "only English-fluent members can read it" or "only English-fluent and German-fluent members can read it" if we had both language versions.

I really don't see what's so terrible about linking to the English translation we have (even if it is just a Babelfish translation that has been modified by an admin fluent in German). I don't see the benefit of blocking out the majority of our members.

I guess if admin was the US Supreme Court, this would be a dissenting opinion.

Thanks, and sorry again. I'm sure this is an excellent article and I wish I could read it.


 
[Link]
pawd wrote on 11/30/2001 at 5:24 PM  
"janwinkler wrote on 11/30/2001 at 12:36 AM I wrote a letter to the evolt team and asked if it is possible to write in german 'cause writing in english could be difficult.
The team said that it would ...etc. etc.. "

If that is bad english, my own English must be catastrophic !

How about this :
If someone wants to, they can publish their articles in both "bad English" and their own language.
That way, everyone gets to be happy.

Would that be a solution ? What do you think ?
 
[Link]

Publishing in English as well

MartinB wrote on 12/01/2001 at 5:06 AM
 

Matt, for the second time: if you want to publish the translation as a comment, there's nothing stopping you. Go ahead, publish and stop complaining.

The decision was that if anyone felt strongly enough about translating an article that they should go ahead and do it. Take some responsibility and do it, rather than demanding that everything be handed to you on a plate.

It's fundamentally patronising and egocentric to demand that everyone else has to publish in my language, but to refuse to publish in theirs. This is not an American community, but a global one. Read the footer to this page, and think about how unwelcoming you're being to the majority of the world's population who don't have English as a first language.

If someone wants to, they can publish their articles in their own language. If you feel that a translation is important, translate it. If the best you have is Babelfish, that's fine.


 
[Link]
cold_logic wrote on 12/01/2001 at 3:19 PM  
Oh, get off your high horse, pawd!

>The International language is ENGLISH !

This is so wrong. Did you know that a third of the world's population speaks Chinese (Mandarin)? German is spoken by 118 million people in the world. That's a significant number.

Many people (including me) speak English as a second language. There's a difference between posting a couple of lines in a forum and writing a full-length technical article. Being able to do the former doesn't automatically mean you can do the latter. Don't go off at Jan about his inability to write a full article in English. If he thought that he could produce a higher quality article in German than in English, he made the right decision.

Like Martin said, this article is better off being here than not . This way, at least a few German-speaking people can appreciate it. If it weren't here, nobody would benefit, and that's not what evolt is about.

>The rest of the world actually speaks English.

And you call the Germans arrogant? Your comments are not just arrogant, but also ignorant. Go read this .

Send in your French article. If it's good, evolt will probably publish that too.

 
[Link]
pawd wrote on 12/01/2001 at 4:06 PM  
Hope someone can read this ;-)

Cold Logic ! Røg du på gulvet da du blev født eller hvad ? Din røv lugter, og din mor er en udbrændt narkoluder på donér !

Cold Logic ! I´m really sorry about being so arrogant. It won´t happen again ! Since I´m able to speak German,
I should´nt have posted anything.
 
[Link]

Re: Publishing in English as well

mwarden wrote on 12/01/2001 at 5:20 PM
 

MartinB wrote:
Matt, for the second time: if you want to publish the translation as a comment, there's nothing stopping you. Go ahead, publish and stop complaining.

There's nothing stopping me? Ok, I guess I'll just ignore the posts on admin saying that we shouldn't?

The decision was that if anyone felt strongly enough about translating an article that they should go ahead and do it. Take some responsibility and do it, rather than demanding that everything be handed to you on a plate.

Wow. We already have a translation. It's not mine. I already have access to it, so nothing would be handed to me on a plate... But, it sounds good the way you misrepresented it, so I guess that's ok.

It's fundamentally patronising and egocentric to demand that everyone else has to publish in my language, but to refuse to publish in theirs.

I couldn't agree more.

This is not an American community, but a global one. Read the footer to this page, and think about how unwelcoming you're being to the majority of the world's population who don't have English as a first language.

Huh? How is having both a German and English version unwelcoming? You have some pretty odd reasoning. From where I'm standing, having only a German version seems more unwelcoming.

If someone wants to, they can publish their articles in their own language. If you feel that a translation is important, translate it. If the best you have is Babelfish, that's fine.

Yeah, I'll say again. We've got one. I wish it was mine, because I'd link to it if it was.

Thanks for your comments, Martin!


 
[Link]

what is... ?

smok wrote on 12/02/2001 at 1:54 PM
 
As I am German, I understand everything .ok , i'm happy. If I would post an article, I would do it in english, as I comment my scripts in english, gernerally. Anyway - You all are just talking about languages, first, or second, english, frensh or dansk. I think you forgot one major thing: The code, and the Idea to read from text-files using Javascript. i guess you all people familiar with javascript could actually read and understand the code or parts of it. I think it is totaly unecessary (everthing spelled right so far? ;-) ) I would prefer using other script languages. Server Based! like php or perl. (or asp if you have a windows server). not just for security reasons. it's just, that f.e. PERL is just made for accessing and manipulating text files. and php comes with such features as well, and is quite easy.. supports a load of databases ... so for what javascript? ------------ GERMAN: Ihr habt bestimmt alles englische verstanden, oder ihr seid alt und aus der ehem. DDR, oder habt ihr gar die schule nicht besucht? Wird doch bundesweit ab der 5. klasse unterrichtet.... ;-) ------------------ you see, one reason for the janwinkler to write in german is the fact that a complex story can be written in this less text. //smok
 
[Link]

smok

smok wrote on 12/02/2001 at 1:56 PM
 
where are my line-breaks???

sorry didn't know what I must include them with BR
 
[Link]

what is... ?

smok wrote on 12/02/2001 at 1:59 PM
 
As I am German, I understand everything .ok , i'm happy. If I would post an article, I would do it in english, as I comment my scripts in english, gernerally. Anyway - You all are just talking about languages, first, or second, english, frensh or dansk.
I think you forgot one major thing: The code, and the Idea to read from text-files using Javascript. i guess you all people familiar with javascript could actually read and understand the code or parts of it.

I think it is totaly unecessary (everthing spelled right so far? ;-) )

I would prefer using other script languages. Server Based! like php or perl. (or asp if you have a windows server).
not just for security reasons. it's just, that f.e. PERL is just made for accessing and manipulating text files. and php comes with such features as well, and is quite easy.. supports a load of databases ... so for what javascript?

------------
GERMAN:
Ihr habt bestimmt alles englische verstanden, oder ihr seid alt und aus der ehem. DDR, oder habt ihr gar die schule nicht besucht? Wird doch bundesweit ab der 5. klasse unterrichtet.... ;-)
------------------

you see, one reason for the janwinkler to write in german is the fact that a complex story can be written in this less text.

//smok


ps- now i figured it out ;)

 
[Link]

ClientSide or ServerSide

janwinkler wrote on 12/02/2001 at 2:32 PM
 
smoke:
"... so for what javascript?"
The text describes posibilities how to access to text-files with javascript not because i like to do it with js but because some people asked me how they could do things like that ... so i created the article. As you can read as 'Fazit' (What's this in englis? grrr.) I also don't like to use JS for these things ... ;-)

"Ihr habt bestimmt alles englische verstanden, oder ihr seid alt und aus der ehem. DDR, oder habt ihr gar die schule nicht besucht? Wird doch bundesweit ab der 5. klasse unterrichtet.... "
Was soll das jetzt? Ja, ich komme aus dem Osten, habe aber dennoch mehr als 8 Jahre englischen Unterricht genossen (den es nebenbei auch bei uns gab - man mag es kaum glauben) ...

jan.
 
[Link]

Text is still good

pawd wrote on 12/02/2001 at 3:28 PM
 
I hope the relation here is altight !

You can update Flashfiles on the fly using xml to pull out the content from a textfile
You could call it "poor mans CM System".
This could (almost) have been done with actionscripting as well, but the sorting into movieclips would have turned out be a lot more difficult
You can see the result here : www.dr.dk/orbitalen/tidslinier/
Once you´re there, click the link "Computerens historie" (located in the center of the page)

Hope this contributes to Jan´s article !
 
[Link]

Fazit

wolf wrote on 12/02/2001 at 5:56 PM
 
summary
 
   Add your comment:  
 

Want to join the conversation? You need to log in to post a comment! You can enter your username and password on the right. If you aren't a member of evolt.org yet, register and become a part of the discussion!

 
Search evolt.org
[Advanced Search]




 

Submit

Contact


Recent Jobs



Highest Rated Articles


Recent Hot Discussions