Jquery Manage The Local File System

 

jQuery.twFile

This jQuery plugin provides access to the local file system (for documents loaded from afile:// URI) to load and save file contents from the browser.

The code is based on TiddlyWiki's self-saving capabilities.

Note that the TiddlySaver applet is required on Opera and WebKit-based browsers (Safari, Chrome). The applet has to be present in the same folder as the respective HTML document.

Source

The source code is currently hosted in TiddlyWiki's Subversion repository.

Feedback is welcome.

API Summary

  • $.twFile.load(filePath): load contents from file

  • $.twFile.save(filePath, content): save contents to file

  • $.twFile.copy(dest, source): duplicate existing file

    N.B.: This is not supported on all browsers.

  • $.twFile.convertUriToLocalPath(filePath): normalizes specified absolute file path

N.B.: All file paths must be absolute (e.g. /tmp/foo.txt orC:\temp\foo.txt).

(full documentation in the code comments)

Limitations

  • plugin unavailable until document.ready handlers have completed

    Since the TiddlySaver applet cannot be injected synchronously into the document, this is done asynchronously duringdocument.ready processing.

    This means that the plugin is not guaranteed to work properly until after all these handlers have completed.

  • currently unreliable UTF-8 support on Internet Explorer

    The plugin is designed to work with UTF-8 encoded text files. However, support in Internet Explorer is broken, and can only reliably save files that are encoded with the ANSI subset of UTF-8. In the case of HTML files, this problem can often be avoided by using HTML entity encodings.

Internals

Internally, the plugin uses four separate drivers to implement the functionality on different browsers:

  • activeX: uses the FileSystemObject built into Internet Explorer 5 and above
  • mozilla: uses the XUL libraries built into Firefox
  • tiddlySaver: uses a custom Java applet that works on Safari, Chrome and Opera
  • javaLiveConnect: uses an ancient (and slow) binding technology to call Java runtime library routines directly - only works on Opera

Besides, yo can copy and paste follow code into your page, by the way, please pay attention that you have invoke Jquery library.

 

<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>

 

<script type="text/javascript" language="JavaScript">

 

$(document).ready(function () {

$.get('Files/requested_file.htm', function (html) {  //modify'Files/requested_file.htm' to your file path

 

 alert(html);

});

});

 

</script>

 

 

Demo

Download this document (andTiddlySaver if necessary) and open it from the local disk.

This demo illustrates self-saving capabilities by passing document.location.href to$.twFile.convertUriToLocalPath, using the return value in load and save functions.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值