
download: This is the name of the file you're downloading.target="_blank" : This indicates a new tab should be opened, it's not essential, but it helps guide the browser to the desired behavior.And then a comma separates it from the link we want to download. href="data:video/mp4," : Here we are setting the link to the a data: with a header preconfigured to video/mp4.Documentation:ĭata URLs are composed of four parts: a prefix (data:), a MIME type indicating the type of data, an optional base64 token if non-textual, and the data itself. Download Videoīecause we use a Data URL, we are allowed to set the mimetype which indicates the type of data to download. Just set the href attribute to "data:(mimetypeheader),(url)". The name of the file can be set using the attribute value name, if not provided then the original filename will be used.

This can be solved 100% entirely with HTML alone. Approach 1: Using Download attribute The download attribute simply uses an anchor tag to prepare the location of the file that needs to be downloaded. Initiate_user_download('data.csv', 'text/csv', 'Sample,Data,Here\n1,2,3\n')

Here is a pure JavaScript solution I tested working in Firefox and Chrome but not in Internet Explorer: function downloadDataUrlFromJavascript(filename, dataUrl) )
