Skip to content

Instantly share code, notes, and snippets.

@powerslacker
Last active December 20, 2019 15:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save powerslacker/7d4e4b5c2f6898cf6a40bc12a236cbbb to your computer and use it in GitHub Desktop.
Save powerslacker/7d4e4b5c2f6898cf6a40bc12a236cbbb to your computer and use it in GitHub Desktop.
html5 download attribute workaround
<!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