這看起來像一個基本的問題,但未能找到答案..有什麼我需要添加的按鈕,使用戶到主頁和播放聲音?目前它只播放聲音。我希望它立即播放聲音,然後進入主頁。爲什麼我的按鈕不能播放我的聲音並轉到鏈接?
function playBeep() {
var sound = document.getElementById("Sound")
sound.play()
}
<div class="animatedButton">
<audio id="Sound" src="https://www.soundjay.com/button/sounds/beep-07.mp3"></audio>
<a href="Home.html"> </a>
<button id="aButton" onclick="playBeep()">
<img src="img/Home.png">
</button>
</div>
你在哪裏告訴瀏覽器導航到一個新的頁面?如果您立即更改頁面,用戶將聽不到聲音。 – PeterMader
我已經創建了用戶點擊進入主頁按鈕的按鈕,animatedButton是應該播放聲音然後鏈接的按鈕。 –
因爲按鈕和「」元素之間沒有連接。爲此,您需要在音頻完成時設置location.href([示例])(https://stackoverflow.com/questions/11103582/detecting-when-html5-audio-is-finished-playing-more-than-一次)) - 但是像這樣的自定義音頻可能會很煩人。也不要直接鏈接到soundjay。 –