<!DOCTYPE HTML>
<head>
<title>JS实现报警提示音</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<script src="./jquery.min.js"></script>
<script type="text/javascript">
function playSound() {
var borswer = window.navigator.userAgent.toLowerCase();
if(borswer.indexOf('ie') >= 0) {
var strEmbed = '<embed name="embedPlay" src="./1.mp3" autostart="true" hidden="true" loop="false" />';
if($('body').find('embed').length <= 0) {
$('body').append(strEmbed);
}
var embed = document.embedPlay;
//浏览器不支持audio,则使用embed播放
embed.volume = 100;
} else {
//非IE内核浏览器
var strAudio = '<audio id="audioPlay" src="1.mp3" hidden="true" />';
if($('body').find('audio').length <= 0) {
$('body').append(strAudio);
}
var audio = $('#audioPlay');
audio.play();
}
}
</script>
</head>
<body>
<input type="button" value="点击提示音" onclick="playSound()" />
</body>
</html>