Anchor download Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

The download property sets or gets the value of the download attribute of an anchor link.

Property Values

ValueDescription
filename Set text to be used as the filename. If omitted, the original filename is used.

Return Value

A String, representing the name of the downloaded file

The following code shows how to Display the value of the download attribute of a link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<a id="myAnchor" href="http://java2s.com/resources/a.png" download="myDownloadFileName">
<img border="0" src="http://java2s.com/resources/a.png" alt="alt message" width="104" height="142"></a>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from   w w  w  .j a v a  2  s . com
    var x = document.getElementById("myAnchor").download;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials