Monday, May 14, 2012

Download Attribute Overriding onClick <a>

I am using the download attribute to trigger a forced download of a song, but it seems to be overriding the onClick event. I can only do one or the other.



<output></output>
<input onclick="window.close()" type="button" value="Cancel"/>

<script>
var a = document.createElement("a");
a.download = song + ".mp3"
a.href = url
a.onclick = function(e) {
var notification = webkitNotifications.createHTMLNotification(
'notification2.html'
);
notification.show();
window.close();
}
document.getElementsByTagName("output")[0].appendChild(a);
document.getElementsByTagName("a")[0].innerHTML = "Download"
</script>


How do I both trigger the download, and fire the onClick event?





No comments:

Post a Comment