Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

download file javascript

function download(link) {
  var element = document.createElement('a');
  element.setAttribute('href', link);

  element.style.display = 'none';
  document.body.appendChild(element);

  element.click();

  document.body.removeChild(element);
}
Comment

javascript download file

let data = JSON.stringify([{email: "test@domain.com", name: "test"}, {email: "anothertest@example.com", name: "anothertest"}]);

let type = "application/json", name = "testfile.json";
downloader(data, type, name)

function downloader(data, type, name) {
	let blob = new Blob([data], {type});
	let url = window.URL.createObjectURL(blob);
	downloadURI(url, name);
	window.URL.revokeObjectURL(url);
}

function downloadURI(uri, name) {
    let link = document.createElement("a");
    link.download = name;
    link.href = uri;
    link.click();
}
 Run code snippet
Comment

javascript download file

$('a#someID').attr({target: '_blank', 
                    href  : 'http://localhost/directory/file.pdf'});
Comment

download file using Javascript

<iframe id="my_iframe" style="display:none;"></iframe>
<script>
function Download(url) {
    document.getElementById('my_iframe').src = url;
};
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: fabric js 
Javascript :: javscript randomly generate 89digit number 
Javascript :: How to find out what character key is pressed?#key#keyCode#code 
Javascript :: javascript find method 
Javascript :: chaine de caractère dans une autres js 
Javascript :: how to clear all slash commands 
Javascript :: Authomatically set an environment variable from response in postman 
Javascript :: mouse over jest 
Javascript :: does kendo window content clear on close 
Javascript :: javascript const 
Javascript :: JavaScript - Closures 
Javascript :: babel compile files empty 
Javascript :: javascript remove everything after . 
Javascript :: delegate click in jquery 
Javascript :: svg event listeners 
Javascript :: sort array of objects based on another array javascript 
Javascript :: mongoose encrypt database using mongoose encryption package 
Javascript :: javascript prevent right click 
Javascript :: ERROR TypeError: By.Subject is not a constructor 
Javascript :: javascript function declaration vs arrow function 
Javascript :: The loading of x in a frame is denied by “X-Frame-Options“ directive set to “SAMEORIGIN“ js 
Javascript :: javascript Use clearTimeout() Method 
Javascript :: find consecutive numbers in an array javascript 
Javascript :: select div with clas 
Javascript :: how to prevent render in react 
Javascript :: creating room in ws nodejs 
Javascript :: node js create pdf from html 
Javascript :: moyenne javascript 
Javascript :: shopify api for add to cart 
Javascript :: daysjs 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =