This code is working fine on jsFiddle but not on my system.
JsFiddle
I have checked from the draft (Pressing Ctrl + Shift + Enter on jsFiddle), added this code to head section & modified like below:
window.addEvent('load', function() {
window.webkitRequestFileSystem(window.TEMPORARY, 2*1024*1024, function(fs) {
fs.root.getFile('test', {create: true}, function(fileEntry) {
alert(fileEntry.toURL());
fileEntry.createWriter(function(fileWriter) {
var builder = new WebKitBlobBuilder();
builder.append("Saurabh");
builder.append("\n");
builder.append("Saxena");
var blob = builder.getBlob('text/plain');
fileWriter.onwriteend = function() {
// navigate to file, will download
location.href = fileEntry.toURL();
};
fileWriter.write(blob);
}, function() {});
}, function() {});
}, function() {});
});
You get a
FileError.SECURITY_ERRbecause you are not allowed to run this code locally. You would see the error if you didn’t have empty errorhandlers.You will see the error if you save the following code to a local file and run it in chrome: