Commit 5c155e48 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

+downloading support for firefox

parent 684cb0c7
...@@ -26,6 +26,13 @@ function parseURL(){ ...@@ -26,6 +26,13 @@ function parseURL(){
$(function(){ $(function(){
$.ajax({
url: "http://192.168.0.9:2323",
success: function(){
console.log("success");
}
});
parseURL(); parseURL();
init(); init();
......
...@@ -59,17 +59,79 @@ function download_all(rtp){ ...@@ -59,17 +59,79 @@ function download_all(rtp){
function download_single(addr){ function download_single(addr){
// get ze blob
var http = new XMLHttpRequest();
http.open("GET", addr, true);
http.responseType = "blob";
http.onload = function(e){
if (this.status === 200) {
// To access the header, had to add
// printf("Access-Control-Expose-Headers: Content-Disposition\r\n");
// to imgsrv
var filename = this.getResponseHeader("Content-Disposition");
pass_to_file_reader(filename,http.response);
}
}
http.send();
/*
return 0;
var link = document.createElement('a'); var link = document.createElement('a');
link.setAttribute('download', null); link.setAttribute('download', null);
link.style.display = 'none'; link.style.display = 'none';
document.body.appendChild(link); link.download = addr;
link.href = addr;
link.setAttribute('href', addr); document.body.appendChild(link);
link.click(); link.click();
document.body.removeChild(link); document.body.removeChild(link);
*/
}
// from here:
// https://diegolamonica.info/multiple-files-download-on-single-link-click/
// http://jsfiddle.net/diegolamonica/ssk8z9pa/
function pass_to_file_reader(filename,filedata){
var parameters = filename.split(";");
for (var i=0;i<parameters.length;i++) parameters[i]=parameters[i].split("=");
for (var i=0;i<parameters.length;i++) {
if (parameters[i][0].trim()=="filename"){
filename = parameters[i][1].replace(/"/ig,"");
filename = filename.trim();
}
}
var reader = new FileReader();
reader.filename = filename;
reader.onloadend = function(e){
var file = [this.filename,e.target.result];
var theAnchor = $('<a />')
.attr('href', file[1])
.attr('download',file[0])
// Firefox does not fires click if the link is outside
// the DOM
.appendTo('body');
theAnchor[0].click();
//theAnchor.click();
theAnchor.remove();
};
reader.readAsDataURL(filedata);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment