Javascript Knowledge

  • what is javascript

  • javascript Variable
  • javascript function
  • javascript Event

  • JavaScript If
  • javascript for

  • javascript object
  • Javascript String
  • Javascript Date
  • Javacsript Array
  • Javascript Math

  • Javascript onclick
  • JavaScript onload

  • Javascript Frame
  • Javascript Image
  • Javascript Style
  • Javascript Textarea
  • Javascript Table
  • Javascript window
  • Javascript Location
  • Javacsript form
  • Javascript Checkbox
  • Javascript Input
  • Javascript Radio
  • Javascript Select
  • Javascript Submit

  • Javascript alert
  • Javascript close
  • Javascript confirm
  • Javascript Document open
  • Javascript getElementById
  • Javascript print
  • Javascript reload
  • Javascript remove
  • JavaScript replace
  • Javascript setTimeout
  • JavaScript split
  • JavaScript substring
  • Javascript window open
  • window showmodaldialog

  • Javascript href
  • Javascript IFrame
  • Javascript innerHTML
  • Javascript selectedindex
  • Javascript URL
  • Javascript window Location

  • javascript write to file
  • JavaScript write
  • javascript string to integer
  • Javascript popup
  • Javascript return
  • Javascript Obfuscator
  • Javascript disable
  • Javascript Hide
  • More others

    Javascript
    CSS
    PHP

     

    Javascript write to file


    Javascript write to file

    Are you looking for the ways to access the file system using JavaScript? If your JavaScript code could access local files of the visitor to your site, it would be a huge security problem. That's why no browsers would allow it...

    JavaScript is a simple yet very powerful scripting language. Why not use your knowledge of JavaScript for batch processing of local files and other common tasks?
    Well, you can! Not through the Internet of course, but internally on your computer, or on your intranet if you have one.

    How can you use JavaScript to access your local files and folders? Currently there are two ways to do it:

    1. Using JavaScript extensions (runs from JavaScript Editor), or
    2. Using a web page and ActiveX objects (Internet Explorer only)

    Using ActiveX objects gives you many possibilities, but there are two distinct disadvantages:

    You need a web page to run your JavaScript, and
    ActiveX objects only work with the Internet Explorer browser.

    When using extensions, all you need to do is select Build / Execute from the menu and let JavaScript Editor do the job.

    Example 1 (using extensions): Reading a file

    1. Run JavaScript Editor
    2. Copy and paste the code below
    3. Save the file as FileRead.js, and
    4. Select Build / Execute from the menu.

    Note: If you do not save the file, getScriptPath() below will return an empty string.

    // This example shows file manipulation routines: it echoes
    // the contents of itself (the script file).
    // Created with Antechinus® JavaScript Editor
    // Copyright© 2000-2005 C Point Pty Ltd

    fh = fopen(getScriptPath(), 0 ); // Open the file for reading
    if (fh!=- 1 ) // If the file has been successfully opened
    {
        length = flength(fh);         // Get the length of the file    
        str = fread(fh, length);     // Read in the entire file
        fclose(fh);                     // Close the file
        
    // Display the contents of the file    
        write(str);    
    }

    Example 2 (using extensions): Listing files in a folder

    1. Run JavaScript Editor
    2. Copy and paste the code below
    3. Save the file as FolderExample.js, and
    4. Select Build / Execute from the menu.

    Note: if you do not save the file, getCurrentFolder() below will return an empty string.

    // This example shows folder manipulation routines: it lists
    // the contents of the current folder.
    // Created with Antechinus® JavaScript Editor
    // Copyright© 2000-2006 C Point Pty Ltd

    write( "The contents of " + getCurrentFolder());

    fileName = findFirstFile( "*.*" ); // Find the first file matching the filter
    while (fileName.length)
    {
        write(fileName);
        fileName = findNextFile();  // Find the next file matching the filter
    }

    Example 2 (using ActiveX and a web page): Listing available drives

    1. Run JavaScript Editor
    2. Copy and paste the code below
    3. Save the file as DriveList.htm, and
    4. View the page using Internal Viewer or Internet Explorer


    < HTML >
    < HEAD >

    < SCRIPT language = JavaScript>

    function ShowAvailableDrives()
    {
        document.write(GetDriveList());
    }

    function GetDriveList()
    {
    &nbspvar fso,  s,  n,  e,  x;
     fso  = new ActiveXObject( "Scripting.FileSystemObject" );
     e  = new Enumerator(fso.Drives);
     s  =  "" ;
    &nbspdo
     {
       x  =  e.item();
       s  =  s  +  x.DriveLetter;
       s  +=  ":-    " ;
      &nbspif (x.DriveType  ==  3 )     n  =  x.ShareName;
      &nbspelse if (x.IsReady)     n  =  x.VolumeName;
      &nbspelse                     n  =  "[Drive not ready]" ;
       s  +=  n  +  "<br>" ;
       e.moveNext();
     } &nbspwhile (!e.atEnd());
     
    &nbspreturn (s);
    }

    </ SCRIPT >
    </ HEAD >

    < BODY >
    < P>
    < SCRIPT language=JavaScript>  ShowAvailableDrives(); </ SCRIPT>
    </ P>
    </ BODY>
    </ HTML >

    Putting it all together:

    Use JavaScript for batch processing and other common tasks of your local and intranet files
    Using ActiveX objects works well, but you need a web page to run your JavaScript
    ActiveX objects work on Internet Explorer, but not on Opera, Netscape or Firefox
    When using JavaScript extensions you do not need a web page: run your code straight from the JavaScript Editor.

     





















     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

  • Javascript |