getting text files from a server for use in a dHTML layer

They have: 2 posts

Joined: Dec 1999

Is there a JavaScript script (no Java) which can download a text file from a server and put the content of that file in a dHTML layer? I need this for a news ticker script, but most of them are in Java, or use images instead of text.

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

JavaScript can only read from a .js file and from a cookie, but not a plain text file. You might be able to set a bunch of string variables to hold the contents of the layer (tags, etc.) and then use document.write() on the page to call them.

I haven't tried it out yet though.

They have: 2 posts

Joined: Dec 1999

Yes, i did this before and it worked, but i can't figure out how to create a link in the document.write. i tried it this way:
document.write("<a href="http://www.anything.
com>click here!</a>");
but it didn't work... Any sugestions?

They have: 5,633 posts

Joined: Jan 1970

When using the document.write script there are some charachters which are read as JavaScritp when they should be read as html, these include "/". to prevent it being read as JavaScript you have to use the "\" character, this escapes JavaScript for the character which follows it.

So you want something like this

Code Sample:

document.write("&lt;a href=http:\/\/www.someplace.com&gt;Click Me&lt;\/a&gt;");

This should work.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.