0

我正在使用下載屬性觸發強制下載歌曲,但它似乎是重寫onClick事件。我只能做一個或另一個。下載屬性覆蓋onClick <a>

<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> 

如何觸發下載並觸發onClick事件?

回答

1

嘗試使用addEventListener

a.addEventListener("click", function (e) { 
    var notification = webkitNotifications.createHTMLNotification(
     'notification2.html' 
    ); 
}); 
+0

現在事件觸發,但下載並非如此。 –

+0

你在使用'manifest_version:2'嗎?這可能是HTML/JavaScript分離問題嗎? – apsillers

+0

你在哪裏檢查清單版本? –