Abe Miessler
Abe Miessler

Reputation: 85036

Accessing file system using javascript in firefox or chrome?

I had been able to do this up until Firefox 15 using:

netscape.security.privilegeManager.enablePrivilege("UniversalXPConnect")

and setting the signed.applets.codebase_principal_support option to true. Unfortunately as of FF 17 this functionality has been removed. From what I understand Chrome has been the same way for some time now.

Does anyone know if there has been a Firefox or Chrome extension created that allows for the use of enablePrivilege? If not, recommendations on where to start if building my own?

Upvotes: 1

Views: 1111

Answers (1)

Ryan
Ryan

Reputation: 5682

File API, the reason those have stopped working is because both have now implemented the html5 file api.

Here is a html5 demo of the api.

Here is the relevant script in case they remove the demo:

<script>
var holder = document.getElementById('holder'),
state = document.getElementById('status');

if (typeof window.FileReader === 'undefined') {
 state.className = 'fail';
} else {
 state.className = 'success';
 state.innerHTML = 'File API & FileReader available';
}

holder.ondragover = function () { this.className = 'hover'; return false; };
holder.ondragend = function () { this.className = ''; return false; };
holder.ondrop = function (e) {
this.className = '';
e.preventDefault();

 var file = e.dataTransfer.files[0],
 reader = new FileReader();
 reader.onload = function (event) {
    console.log(event.target);
    holder.style.background = 'url(' + event.target.result + ') no-repeat center';
 };
 console.log(file);
 reader.readAsDataURL(file);

 return false;
};
</script>

As a note: if you need to access a file on your local machine in chrome you need to run the program using this switch --allow-file-access-from-files (for using a file input without it actually loading to the server, otherwise you get a xhr cross-domain error).

I don't know of the equivalent in firefox.

Upvotes: 2

Related Questions