Accessing a variable in another file & file ops.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter

    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
  • Randell D.

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


    "Peter" <ptrlsn@hotmail .com> wrote in message
    news:5ebd9070.0 307120229.4a9a1 b0c@posting.goo gle.com...[color=blue]
    > 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[/color]

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


    Comment

    • Laurent Bugnion, GalaSoft

      #3
      Re: Accessing a variable in another file &amp; file ops.

      Hi,

      Peter wrote:[color=blue]
      > 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?[/color]

      You must include your other JS file with

      <SCRIPT LANGUAGE="JavaS cript" TYPE="text/javascript"
      SRC="yourOtherF ile.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.

      [color=blue]
      > 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).[/color]

      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.

      [color=blue]
      > Thanks
      > /Peter[/color]

      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

      Comment

      • Peter

        #4
        Re: Accessing a variable in another file &amp; file ops.

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

        function buildPage(showC ontent) { // see below for info on
        *showContent*
        var header = "<html><head><t itle>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

        Comment

        Working...