JavaScript
x
13
13
1
<button id="btn" onclick="download(http://imageurl) value ="download"><button>
2
3
4
<script>
5
function download(url){
6
console.log(url);
7
var link = document.createElement('a');
8
link.href = url;
9
link.download = "image.jpg";
10
document.body.appendChild(link);
11
link.click();}
12
</script>
13
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:
JavaScript
1
2
1
<button id="btn" onclick="download('http://imageurl')" value ="download"><button>
2