在一些客服系统中,当有新消息出现时,会有提示声音响,使用到的是html5的新标签
<audio id="chatMessageAudio"> <source id="chatMessageAudioSource" src="/static/images/alert.mp3" type="audio/mpeg" /> </audio>
当有新消息时就可以直接调用了
var b = document.getElementById("chatMessageAudio"); var p = b.play(); p && p.then(function(){}).catch(function(e){});
效果可以点击在线交流进行测试