473,372 Members | 961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Accessing a variable in another file & file ops.

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
3 12353

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Lamberti Fabrizio | last post by:
Hi all, I've to access to a network file from an asp pages. I've red a lot of things on old posts and on Microsoft article but I can't still solve my problem. I've got two server inside the...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
4
by: Khalique | last post by:
I have built a web service whose purpose is to copy files from a secure place to client machine and vice versa. The problem I am having is perhaps related to permissions and access rights. For...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
2
by: Jurek Dabrowski | last post by:
hi all, I have a question in reference to accessing variables in another class maybe someone has dealt with before. I have some public variables declared in my main plug-in class...
4
by: John Kotuby | last post by:
Hi all, I am using a Repeater in conjunction with a SQLDatasource and SQL Server. One of the controls in the repeater is a HyperlLink as follows: <asp:HyperLink...
12
by: titan nyquist | last post by:
I have a class with data and methods that use it. Everything is contained perfectly THE PROBLEM: A separate thread has to call a method in the current instantiation of this class. There is...
3
by: djsuson | last post by:
I'm trying to set up an inheritance tree that also uses templates. This is an attempt to simplify some previous code that was filled with redundancies. I'm working with g++ 3.4.6. The code is split...
2
by: Newbie | last post by:
Hi, I have a situation where my application is trying to access a file, that another application may have temporalily open. The error I get is The process cannot access the file...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.