Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2004
    Location
    Nagoya, Japan
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I can't read these txt file,using the File Object

    Hi there.I need to get some information from a txt file that I'm using as a simple database,but I have not succeed so far.
    Can you tell me what is wrong in these function?I consulted the File Object manual,but I think everything is fine!

    function open_file()
    {
    var x;
    var info = new File("filename.txt");
    if(info.open("r"))
    {
    while(!info.eof()){
    x = info.readln();
    }
    info.close();
    }
    }
    </script>
    <input type="button" name="search_button" onClick="open_file()" value="search">

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts

    There is no File object!

    Javascript can't read the contents of a text file without ActiveX and IE or XMLHTTP.

    //activex
    var fso = new ActiveXObject('Scripting.FileSystemObject');

    For more details of FSO, click this. It's VBScript but the methods and properties are the same, just follow the camelCasing convention of property and method names.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post
    Well I have a sorta cheesy method that works: you simply have a iframe in a div were the visibility is hidden. You then set the url of the iframe to the text file and get the innerHTML of the iframe. Of course this will not work over different domains.
    Kris Hubby
    kwhubby site


  •  

    Posting Permissions

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