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 :: onchange not working input jquery 
Javascript :: sequelize delete item 
Javascript :: FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory 
Javascript :: get number from string using jquery 
Javascript :: get css custom property javascript 
Javascript :: javascript flatten an array 
Javascript :: ajax post variable values 
Javascript :: uuid timestamp for javascript 
Javascript :: include jsp in another jsp 
Javascript :: split in mongodb 
Javascript :: AWS S3 JavaScript example 
Javascript :: javascript classlist add 
Javascript :: javascript is number even or odd 
Javascript :: js bundle with popper bootstrap 
Javascript :: Vuejs watch for nested data 
Javascript :: fetch in for loop javascript 
Javascript :: mongoose find one and update with new field 
Javascript :: button onclick enter key 
Javascript :: how to create a random number generator in javascript 
Javascript :: add key vakue to front of object 
Javascript :: jquery animation 
Javascript :: how to turn a number negative in javascript 
Javascript :: how to auto refresh a div js 
Javascript :: url in js 
Javascript :: capitalize first letter after character javascript 
Javascript :: get placeholder innerhtml 
Javascript :: delete multiple keys from object javascript 
Javascript :: This version of CLI is only compatible with Angular versions 0.0.0 || ^9.0.0-beta || =9.0.0 <10.0.0, but Angular version 10.0.14 was found instead. 
Javascript :: is material ui not working with react 18 
Javascript :: express return json 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =