【问题标题】:Trying to get a button to refresh the page after the sound stops. The sound starts when the button is pressed试图在声音停止后获得一个按钮来刷新页面。按下按钮时声音开始
【发布时间】:2019-02-10 19:36:30
【问题描述】:

仅在声音停止播放后才尝试获取刷新页面的按钮。 我尝试了onend 事件,但没有成功。

function play() {
  var audio = document.getElementById("audio");
  audio.play();
}

function myFunction() {
  location.reload(1);
}
<button onclick="myFunction()">Reload page</button>

<img src="./images/play.png" value="PLAY" onclick="myFunction();play()">
<audio id="audio" src="./Sounds/Casino4.wav"></audio>

播放按钮目前仅刷新页面但您可以听到启动声音,但页面在停止之前刷新。

【问题讨论】:

标签: javascript php html


【解决方案1】:

试试

var audio = document.getElementById("audio");
audio.onended = function() {
    // Your function here
}; 

结束事件在音频/视频到达结尾时发生。 >>https://www.w3schools.com/tags/av_event_ended.asp

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-08
    • 1970-01-01
    相关资源
    最近更新 更多