I have written the following code to create a file using a blob and open it automatically(instead of downloading) in the browser(Chrome).
var saveData = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (data, fileName) {
var json = JSON.stringify(data),
blob = new Blob([json], {type: "text/html"}),
url = window.URL.createObjectURL(blob);
window.open(url);
window.URL.revokeObjectURL(url);
};
}());
var data = { x: 42, s: "hello, world", d: new Date() },
fileName = "my-download.json";
saveData(data, fileName);
JSfiddle : http://jsfiddle.net/cW7W5/6111
The file open successfully in a new browser window as
blob:http%3A//fiddle.jshell.net/83999d68-4d79-4a06-a83d-e40a8b1f9681
But what I want to open it in a url that I specified. For example
blob:http%3A//fiddle.jshell.net/exapmle.txt