<button id="btn" onclick="download(http://imageurl) value ="download"><button>
<script>
function download(url){
console.log(url);
var link = document.createElement('a');
link.href = url;
link.download = "image.jpg";
document.body.appendChild(link);
link.click();}
</script>
Syntax error: ) missing after the argument list?
Advertisement
Answer
You are missing quotes in the HTML. Both the close ” for the onclick attribute, and you need to wrap your parameter in single quotes to make it a string:
<button id="btn" onclick="download('http://imageurl')" value ="download"><button>