<a href="style.css">Download our CSS</a>
当我在 Chrome 中单击它时,它会在浏览器中打开 CSS。如何强制文件下载onclick?
<a href="style.css">Download our CSS</a>
当我在 Chrome 中单击它时,它会在浏览器中打开 CSS。如何强制文件下载onclick?
Special HTTP response headers are required to make the browser force download a file. So for example if you're using PHP a simple example would be this -
<?php
// We'll be outputting a CSS
header('Content-type: text/css');
// It will be called style.css
header('Content-Disposition: attachment; filename="style.css"');
// The CSS is in style.css
readfile('style.css');
?>
It doesn't matter what backend language (PHP/Ruby/Python/Node.js) you're using, just send those specific HTTP headers in the response.