JSFiddle - React, Tailwind, and code Playground

by chiragvidani

JavaScript

$(document).ready(function() {
		saveFile("Example.txt", "data:attachment/text", "Hello, world.");
});

function saveFile (name, type, data) {
	if (data != null && navigator.msSaveBlob)
		return navigator.msSaveBlob(new Blob([data], { type: type }), name);
	var a = $("<a id='previewFile' style='display: none;'/>");
  var url = window.URL.createObjectURL(new Blob([data], {type: type}));
	a.attr("href", url);
	a.attr("download", name);
	$("body").append(a);
  $('#previewFile').click();
	//a[0].click();
  window.URL.revokeObjectURL(url);
   //$('#previewFile').remove();
}