SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Reading from files

    Hey,

    Is there anyway I can use Javascript to read from a file? Here's how I want to use it -
    PHP Code:
    function updateNav(nav)
    {
       switch ( 
    nav )
       {
          case 
    'people':
             var 
    file readFile('people.txt'); // read from the file
             
    document.getElementById('subnav').innerHTML file;
             break;
          
    // etc...
       
    }

    Thanks

  2. #2
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Clientside Javacript cannot read from client's machine, it would be security problem otherwise.

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do this although it would require the user toe allow an active x. Heres a quick example for you

    Code:
    <script type="text/javascript">
    function mkfile()
    {
       var fso, tf;
       fso = new ActiveXObject("Scripting.FileSystemObject");
       tf = fso.CreateTextFile("c:\\testfile.txt", true);
    
    
       tf.WriteLine("Hello.") ;
       tf.WriteBlankLines(10) ;
       tf.Write ("             from Andrew-J.");
       tf.Close();
    }
    
    mkfile();
    
    </script>

  4. #4
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Ooops, sorry, I didn't make it clear what I wanted. I want to read a file on the server but it needs to be dynamic without refreshing that page, that's why I need Javascript.

    Thanks

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •