Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Reading info from a TXT file 1

Status
Not open for further replies.

Loggos

Programmer
Jun 6, 2003
1
0
0
BR
Javascript Reading info from a TXT file ???
 
If you change the suffix of the text file to ".html" and place it somewhere on a server.

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
hey edward,

I bet you know what you are talking about but can you please be a little bit more specific about how you can read text from a file with javascript.

-Zach
 
what Edward is implying is that there are no ways you can read the content of a file with Javascript.

What are you trying to accomplish exactly?

Gary Haran
==========================
 
you can use ActiveX to read a text file that is on the client. That is if the client has ActiveX scripting enabled.

____________________________________________________
[sub]get the best answer to your questions by asking the best questions "General FAQ" faq333-2924[/sub]
onpnt2.gif
[sub][sup][/sup][/sub]
 
eg:
<script language=&quot;JavaScript&quot;>
var fso;
var txtVals;
fso = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);
f = fso_OpenTextFile(&quot;textfile.txt&quot;, 1);
txtVals = f.ReadAll();
f.Close()
document.write txtVals
</script>

along those lines

____________________________________________________
[sub]get the best answer to your questions by asking the best questions &quot;General FAQ&quot; faq333-2924[/sub]
onpnt2.gif
[sub][sup][/sup][/sub]
 
IE only also BTW

before xutopia says it [lol]

____________________________________________________
[sub]get the best answer to your questions by asking the best questions &quot;General FAQ&quot; faq333-2924[/sub]
onpnt2.gif
[sub][sup][/sup][/sub]
 
how did I know that was coming

xutopia on any M$ component = [flame]

[rofl2]

____________________________________________________
[sub]get the best answer to your questions by asking the best questions &quot;General FAQ&quot; faq333-2924[/sub]
onpnt2.gif
[sub][sup][/sup][/sub]
 
loggos is the one who should answe your question xutpia, but I am also interested. I have an example problem that could use the reading of a text file:

I have a complex(is a pain to copy/paste and and update would require me to edit EVERY page's menu code to match with the others) menu system that resides at the top of the page. I do not want to put this menu system in a frame. I also do not have any server-side scripting capabilities. How could I extract the menu's code out of a text file and have it put into the top portion of the output html file?

(I have by the way done this in php using fread).

hope that makes sense :)
-Zach Ngo
 
jeez, you guys wrote 3 threads before i finished mine... lol

-Zach
 
the text file that i want to read it on the server by the way, not the client.

-Zach
 
I'm sorry onpnt,

Have you ever stopped to wonder why every MS features and components are made to work only under IE? Why can't they support more standards instead?

For example :

Transparent PNG
DOM 1
CSS 1 and 2
ECMAScript 262

Fact is some of us are not using IE or Windows and would love to be able to see the online content that people make.

If you want to understand my point of view there are a slew of sites explaining this :


It's sad most people don't care that they are enslaved to pay their fee to MS just for using their computer.

Gary Haran
==========================
 
xutopia, I hoped you knew I didn't have to be told that. I practice browser complient development while working. It is always considered.

I think the only thing I've ever put on a site that wasn't compatable with most browsers (versions exlluded) was a div on my site that I have thus rewritten to provide other browsers to view them. (time given implementation)

My answer was the only I knew how this could be done. There are some closed doors situations that could ahve benifited from the reply

____________________________________________________
[sub]get the best answer to your questions by asking the best questions &quot;General FAQ&quot; faq333-2924[/sub]
onpnt2.gif
[sub][sup][/sup][/sub]
 
you can dynamically load .js files into <script> tags, if this would help...

<script type=&quot;text/javascript&quot; src=&quot;&quot; id=&quot;oScript&quot;></script>

<script type=&quot;text/javascript&quot;>
var oScript = document.getElementById(&quot;oScript&quot;);
oScript.src = &quot;myFile.js&quot;;
</script>



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
onpnt,

Thanks for explaining yourself. I'm under linux at the moment (except at work where my bosses are pissed off that they can't migrate to linux because of lock-ins by M$).

I'm advocating this to everyone I can that we should move away from non-standard stuff especially with people I know can understand.

I should take diplomacy lessons if I plan to change the world. LOL

Gary Haran
==========================
 
zngo,

The problem as you pose it can be solved several ways. The way I suggested is to make it an HTML file. In this case, you would use frames.

Your menu would reside in a header frame. An iframe might work as well -- I have no experience with those.

I'd recommend against frames in general, though, for a variety of reasons.

There are tools, by the way, that allow for bulk search-n-replace. They make up for Windows woeful lack of a common grep function. I use a little tool called &quot;Windows Search and Replace&quot;:

Perhaps a server-side include would help you, although I have no experience with them, either.

If you are using server-side programming to make your web pages, then you only need your code in a TXT file and just read it using Perl or whatever.

Basically, my first answer is still the only one I can think of that uses nothing more exotic than HTML and JavaScript.

Cheers,


[monkey] Edward [monkey]

&quot;Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!&quot; -- inventor of the cat door
 
What you could do is create whatever HTML code you need common for all your pages and create a javascript function that generates that code for you.
this way the only thing you have to do is call the function at the top of every page.If changes are needed just change the original HTML code and since the function name is not changing your pages will automatically pick up the new code.

Now it's not necessary for you to manually create the code everytime you want the changes. you could use &quot;Javascript generators&quot; that will create all the Javascript for you based on the HTML code you pass them..

Try this one for example


grtfercho çB^]\..
&quot;Imagination is more important than Knowledge&quot; A. Einstein
 
ooooh i get it. I am going to try making an external javascript file that contains the code generator, thanks for your help!

-Zach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top