“Unduh File JavaScript” Kode Jawaban

Unduh 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);
}
Defeated Dotterel

File Unduh JavaScript

let data = JSON.stringify([{email: "[email protected]", name: "test"}, {email: "[email protected]", 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
Frail Fox

JS Unduh File dari WebServer

<iframe id="download_iframe" style="display:none;"></iframe>
<script>
	document.getElementById('download_iframe').src = "/example/example.txt";
</script>

Defiant Duck

File Unduh JavaScript

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

Jawaban yang mirip dengan “Unduh File JavaScript”

Pertanyaan yang mirip dengan “Unduh File JavaScript”

Lebih banyak jawaban terkait untuk “Unduh File JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya