How to force download a file with JavaScript
How do I make an how to force download a file with javascript?
What is a how to force download a file with javascript? How do you make a how to force download a file with javascript? This script and codes were developed by Jelmer on 02 December 2022, Friday.
How to force download a file with JavaScript - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>How to force download a file with JavaScript</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src="js/index.js"></script>
</body>
</html>
How to force download a file with JavaScript - Script Codes CSS Codes
/* How to force download a file. */
How to force download a file with JavaScript - Script Codes JS Codes
setTimeout(function() { url = '//assets.codepen.io/images/codepen-logo.svg'; // downloadFile(url); // UNCOMMENT THIS LINE TO MAKE IT WORK
}, 2000);
// Source: http://pixelscommander.com/en/javascript/javascript-file-download-ignore-content-type/
window.downloadFile = function (sUrl) { //iOS devices do not support downloading. We have to inform user about this. if (/(iP)/g.test(navigator.userAgent)) { //alert('Your device does not support files downloading. Please try again in desktop browser.'); window.open(sUrl, '_blank'); return false; } //If in Chrome or Safari - download via virtual link click if (window.downloadFile.isChrome || window.downloadFile.isSafari) { //Creating new link node. var link = document.createElement('a'); link.href = sUrl; link.setAttribute('target','_blank'); if (link.download !== undefined) { //Set HTML5 download attribute. This will prevent file from opening if supported. var fileName = sUrl.substring(sUrl.lastIndexOf('/') + 1, sUrl.length); link.download = fileName; } //Dispatching click event. if (document.createEvent) { var e = document.createEvent('MouseEvents'); e.initEvent('click', true, true); link.dispatchEvent(e); return true; } } // Force file download (whether supported by server). if (sUrl.indexOf('?') === -1) { sUrl += '?download'; } window.open(sUrl, '_blank'); return true;
}
window.downloadFile.isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
window.downloadFile.isSafari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
Developer | Jelmer |
Username | jelmerdemaat |
Uploaded | December 02, 2022 |
Rating | 3 |
Size | 2,272 Kb |
Views | 26,312 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
CSS only slider | 3,131 Kb |
CSS only loading spinner | 2,086 Kb |
Loading spinner moving bars | 2,025 Kb |
Check comment length to filter unuseful ones | 2,759 Kb |
Animated counter element | 3,412 Kb |
A Pen by Jelmer | 1,718 Kb |
Justified divs, attempt 3 | 1,816 Kb |
Ungrid with gutters | 1,644 Kb |
Justified divs, attempt 2 | 1,795 Kb |
A pure CSS slideshow | 4,471 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
CSS Google Now | Jackmoran | 3,196 Kb |
A Pen by Mike Otis | Mikeotis | 3,185 Kb |
Css color for svg | Ademilter | 2,392 Kb |
Spiralator 9000 | AdmiralPotato | 4,671 Kb |
Basic HTML Slideshow | Tomhodgins | 3,386 Kb |
Box Shadow Effects | Retrofuturistic | 2,143 Kb |
Modal Dialog | Gigaleet | 2,251 Kb |
Addthis_button | Esambino | 1,691 Kb |
Flexbox Test | Icutpeople | 2,486 Kb |
Page Transitions in Backbone | Mikefowler | 3,691 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!