2014-09-01 111 views
2

我正在播放有聲讀物章節並希望它在HTML5音頻文件結束時自動重定向到下一章節文本和音頻的新頁面。當HTML5音頻文件播放完畢後重定向到新頁面

我不是程序員,所以我可以使用一些幫助。

我知道我需要使用addEventListener結束函數類似於下面的內容,但我不知道如何修改它來調用新頁面而不是新的音頻文件。

<audio id="audio" autoplay controls src="song1.mp3" type="audio/mpeg"></audio> 
<script type="text/javascript"> 
    document.getElementById('audio').addEventListener("ended",function() { 
    this.src = "song2.mp3?nocache="+new Date().getTime(); 
    this.play(); 
    }); 
</script> 

回答

0

當您使用

this.src = "song2.mp3?nocache="+new Date().getTime(); 
this.play(); 

您設置的音頻元件的電流源。

如果你想,而不是加載您的當前頁面的新頁面,您可以使用:

window.location = "your_url";