Re: Accessing a variable in another file & file ops.

Giganews Newsgroups
Subject: Re: Accessing a variable in another file & file ops.
Posted by:  Laurent Bugnion, GalaSoft (galasoft-…
Date: Sun, 13 Jul 2003


Peter wrote:
> Hello,
> Two newbie questions:
> 1) I have a javascript file with a function in it. From this function
> I want to access a variable in another javascript file -which is not
> inside a function. I have tried many combinations to do this, but has
> yet to try the right one. How is it done?

You must include your other JS file with

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"

After that, all the variables defined in the other file are available to
the script. All files and partial scripts are loaded in the page, so
that it becomes, in the end, one whole. This can cause problems,
however, especially if 2 global variables have the same name.

> 2) What kinds of file operations can be done in Javascript (save,
> read, write)? As far as I know all file operations are possible using
> Java within your Javascript. But can't it be done using Javascript
> only? (I'm talking file operations on my own files on my ISP's
> server).

I accept that you're speaking about client-side JavaScript. There are so
many possible configurations that it's impossible to detail all of them.
If you're talking about client-side operations on server-side files,
your possibilities are almost zero. All files operations should be
realized on the server, where you can very well use server-side
JavaScript (for example on ASP). A client-side Java applet can list
files in a directory on the server it originates from (if the server
allows directory browsing) and also read a file (text or binary).
Examples at

With the correct permissions set, client-side JavaScript can also use
ActiveX (on IE only) to perform local file operations (list, write,
read...). In Netscape, local file operations can be performed using Java
File objects, once again in a relaxed security environment. But it's not
what you need and I mention it only for memory.

> Thanks
> /Peter

Detail exactly what you're trying to do, and I'll tell you if it's possible.



Laurent Bugnion, GalaSoft
Webdesign, Java, JavaScript:
Support children in Calcutta:



In response to

Accessing a variable in another file & file ops. posted by ptrl… (Peter) on 12 Jul 2003