事情是這個樣子
做了一個web應(yīng)用,有個提交成功的操作廷粒,突然想干一件事窘拯,就是無論成功與失敗都有個提示音效,就像微信收款成功的提醒似的评雌,
話不多說树枫,上代碼
function playSound()
{
var borswer = window.navigator.userAgent.toLowerCase();
if ( borswer.indexOf( "ie" ) >= 0 )
{
//IE內(nèi)核瀏覽器
var strEmbed = '<embed name="embedPlay" src="https://www.xing2020.com/static/flash/success.wav"></embed>';
if ( $( "body" ).find( "embed" ).length <= 0 )
$( "body" ).append( strEmbed );
var embed = document.embedPlay;
//瀏覽器不支持 audion直焙,則使用 embed 播放
embed.volume = 100;
//embed.play();這個不需要
} else
{
//非IE內(nèi)核瀏覽器
var strAudio = "<audio id='audioPlay' src='https://www.xing2020.com/static/flash/success.wav' hidden='true'>";
if ( $( "body" ).find( "audio" ).length <= 0 )
$( "body" ).append( strAudio );
var audio = document.getElementById( "audioPlay" );
//瀏覽器支持 audion
audio.play();
}
}
有需要的親們自行搬走景东,只求點(diǎn)個贊,互相關(guān)注一下奔誓,期待著在簡書能夠遇到同行斤吐,交個朋友I浴!