By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,526 Members | 2,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,526 IT Pros & Developers. It's quick & easy.

Accessing a variable in another file & file ops.

P: n/a
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?

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).

Thanks
/Peter
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Peter" <pt****@hotmail.com> wrote in message
news:5e**************************@posting.google.c om...
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?

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).

Thanks
/Peter


I can't answer your first question (though I suggest either making the code
available via a hyperlink or if its not too huge, including it with your
post in summary form and I'm sure someone would more quickly answer your
question).

With regards to question 2 - Javascript does not permit, nor does it contain
any functionality for disk access of any sort (ie you cannot
read/write/copy/move/whatever a file). This also means that you cannot even
perform anything so simple as a 'dir' or 'ls -l' or whatever command to list
files in a directory...
Jul 20 '05 #2

P: n/a
Hi,

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"
SRC="yourOtherFile.js"></SCRIPT>

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
http://www.galasoft-LB.ch/myjava/Web...Demo/Demo.html

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.

HTH,

Laurent
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #3

P: n/a
Well, I have a .js file with a function in it which can build a html
page. Something like this:

function buildPage(showContent) { // see below for info on
*showContent*
var header = "<html><head><title>SomeTitle</title></head><body>";

var footer = "</body></html>";

var page = header + content + footer; // see below for info on
*content*

document.write(page);
}

The argument *showContent* contains the .js file to access. This .js
file contains a variable called *content* which could look something
like this:

var content = "<p>This is the content</p>";

How do I access this variable? It needs to be in another file as I
have multiple files with the variable *content* containing different
information.

Thanks in advance for any help.

/Peter
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.