src/util/Util.js
/**
 * Offer data as download in the browser.
 *
 * @name module:util.offerDataForDownload
 * @function
 * @public
 * @param {string} filename - the name of the file to be downloaded
 * @param {*} data - the data
 * @param {string} type - the MIME type of the data, e.g. 'text/csv' or 'application/json'
 */
Offer data as download in the browser.
Offer data as download in the browser .
function offerDataForDownload(filename, data, type)
{
	const blob = new Blob([data], { type });
	if (window.navigator.msSaveOrOpenBlob)
	{
		window.navigator.msSaveBlob(blob, filename);
	}
	else
	{
		const anchor = document.createElement("a");
		anchor.href = window.URL.createObjectURL(blob);
		anchor.download = filename;
		document.body.appendChild(anchor);
		anchor.click();
		document.body.removeChild(anchor);
	}
}
function offerDataForDownload ( filename , data , type ) { const blob = new Blob ( [ data ] , { type } ) ; if ( window . navigator . msSaveOrOpenBlob ) { window . navigator . msSaveBlob ( blob , filename ) ; } else { const anchor = document . createElement ( "a" ) ; anchor . href = window . URL . createObjectURL ( blob ) ; anchor . download = filename ; document . body . appendChild ( anchor ) ; anchor . click ( ) ; document . body . removeChild ( anchor ) ; } }
Offer data as download in the browser.
Offer data as download in the browser .