how to access(read/write) local file system from webkit/javascript?

Posted by ganapati hegde on Stack Overflow See other posts from Stack Overflow or by ganapati hegde
Published on 2010-04-13T05:54:19Z Indexed on 2010/04/13 10:13 UTC
Read the original article Hit count: 789

Filed under:
|

Hi, i am using Webkitgtk for rendering my HTML pages.Now,say i am browsing the page, i select some text while reading,i want to save/write down the selected text on my local file say /home/localfile.txt. Is any way to access(read/write) local file system using webkit? In case of firefox, i can do like below.

try {
        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
        alert("Permission to save file was denied.");
    }
    var file = Components.classes["@mozilla.org/file/local;1"]
        .createInstance(Components.interfaces.nsILocalFile);
    file.initWithPath( "/home/localfile.txt" );
    if ( file.exists() == false ) {
        alert( "Creating file... " );
        file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
    }
    var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
        .createInstance( Components.interfaces.nsIFileOutputStream );

    outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 );
    var output = "my data to be written to the local file";
    var result = outputStream.write( output, output.length );
    outputStream.close();

The above code is written in a javascript file and the js file is linked to the html file.When some text is selected,the js function will be called and action will be taken place.How can i achieve the same result using Webkit? Thanks...

© Stack Overflow or respective owner

Related posts about webkit

Related posts about JavaScript