const URL = 'https://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf'
document.getElementById('download').addEventListener('click', (e) => {
e.preventDefault()
download2(URL2, 'test.pdf')
})
window.onload = function() {
download2(URL, 'test.pdf')
}
function download2(url, name) {
fetch(url, {
headers: new Headers({
Origin: window.location.origin
}),
mode: 'cors'
}).then(res => res.blob()).then(blob => {
const a = document.createElement('a')
a.download = name
a.href = window.URL.createObjectURL(blob)
a.click()
a.remove()
window.URL.revokeObjectURL(a.href)
})
}