Last active
December 20, 2019 15:01
-
-
Save powerslacker/7d4e4b5c2f6898cf6a40bc12a236cbbb to your computer and use it in GitHub Desktop.
html5 download attribute workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
</head> | |
<body> | |
<a href="video/small.mp4" download="new-filename">click me!</a> | |
<script> | |
document.querySelectorAll('a[download]').forEach(x => { | |
let url = x.href | |
console.log(url) | |
x.setAttribute('href', 'data:application/octet-stream,' + encodeURIComponent(url)) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment