我想做的是:
我想为测试目的创建一个Chrome扩展。并且这个扩展名应该能够访问本地硬盘驱动器上的目录和文件。
我是怎么做到的:
我在我的file:///*文件中请求manifest.json的权限。然后,我确保选中了复选框Allow access to file URLs。然后,我为一个文件做了一个XHR:
var xhr = new XMLHttpRequest();
xhr.open("GET", 'file://c:/dir/file.name', true);
xhr.onload = function(e) {
console.log('response: ', xhr.response);
}
xhr.send();..。和整个目录的XHR:
var xhr = new XMLHttpRequest();
xhr.open("GET", 'file://c:/dir/', true);
xhr.onload = function(e) {
console.log('response: ', xhr.response);
}
xhr.send();..。至于整个文件系统:
var xhr = new XMLHttpRequest();
xhr.open("GET", 'file:///', true);
xhr.onload = function(e) {
console.log('response: ', xhr.response);
}
xhr.send();发生了什么:
。
<html>
<head>
<script>..。
</script>
<style>..。
</style>
<title id="title"></title>
</head>
<body>
<div id="listingParsingErrorBox" i18n-values=".innerHTML:listingParsingErrorBoxText"></div>
<span id="parentDirText" style="display:none" i18n-content="parentDirText"></span>
<h1 id="header" i18n-content="header"></h1>
<table id="table">
<tr class="header">
<td i18n-content="headerName"></td>
<td class="detailsColumn" i18n-content="headerSize"></td>
<td class="detailsColumn" i18n-content="headerDateModified"></td>
</tr>
</table>
</body>
</html>..。
<script>start("C:\\dir\\");</script>
<script>addRow("..","..",1,"0 B","11/11/11 11:11:11 AM");</script>
<script>addRow("file.name","file.name",0,"4.9 kB","11/11/11 11:11:11 PM");</script>我的问题是:
我能读到简单的文件。但是,我的扩展如何获得一个好的机器可读的目录或整个文件系统的概述呢?谢谢。
编辑:我知道 API的目的是访问沙箱式filesystem://,但是Chrome可能也允许扩展来访问file://。我找不到任何关于从Chrome扩展中访问file://的文档,所以我只能猜测。
发布于 2012-07-12 13:27:10
https://stackoverflow.com/questions/11452758
复制相似问题