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 :: nodemon exclude 
Javascript :: base64 in js 
Javascript :: style through javascript 
Javascript :: Finding Value of Promise With Then Syntax 
Javascript :: apexcharts bar onclick index 
Javascript :: javascript allow only numbers in input alert 
Javascript :: react native login screen 
Javascript :: javascript this Inside Object Method 
Javascript :: strong password javascript 
Javascript :: trigger keydown event javascript 
Javascript :: next js latest 
Javascript :: how to run a react app 
Javascript :: display component in popup angular 8 
Javascript :: Nuxt.js + Electron 
Javascript :: upload file angular rest api 
Javascript :: validator.js 
Javascript :: what is my version of linux mint 
Javascript :: js update query string without refresh 
Javascript :: run two function after one another 
Javascript :: angular post data not sending 
Javascript :: create chart in excel using javascript 
Javascript :: chai js 
Javascript :: file upload in node js 
Javascript :: pluralize javascript 
Javascript :: fastest way to check a number is palindrome 
Javascript :: longest word in a string 
Javascript :: vuex store in js file 
Javascript :: passing functions as props in react 
Javascript :: knex insert multiple rows 
Javascript :: send json by curl 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =