1

わかりました、これは奇妙なものです。次の点を考慮してください。

    <audio id="background_audio" autoplay="autoplay">
      <source src="static/audio/clip.ogg" type="audio/ogg" />
      <source src="static/audio/clip.mp3" type="audio/mpeg" />
    </audio> 
    <a href="#" onclick="document.getElementById('background_audio').muted = true; return false">mute sound</a>

    <!--[if lt IE 9]>
    <bgsound id="background_snd" src="static/audio/clip.mp3" autostart="true" loop="1">
    <a href="#" onclick="document.all['background_snd'].src=''; return false">mute sound</a>
    <![endif]--> 

それは私が望むすべてを行います (IE、FF、Chrome、および Safari でオーディオを自動再生します) が、小さな問題が 1 つあります: Internet Explorer 8 以下では、2 つの「サウンドをミュートする」ボタンがあります。(コードをよく見ると、その理由は明らかです。)

私の質問は次のとおりです。これが起こらないようにすることは可能ですか?

4

2 に答える 2

2

更新:以下のより良い解決策。

ページの下部にあるタグを使用して<script>、ID「normal_browser_control」を最初のオーディオ ミュート コントロールに追加できます。

ミュート制御:

<a href="#" id="normal_browser_control" onclick="document.getElementById('background_audio').muted = true; return false">mute sound</a>

MSDN のコードを使用した JS:

<script><!--
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

var ie_ver = getInternetExplorerVersion();

if(ie_ver > 0 && ie_ver < 9) document.getElementById('normal_browser_control').style.display = 'none';
//--></script>

:)

于 2011-06-22T16:28:23.280 に答える
1

それとももっと簡単...

2 つの異なるタグを使用できます。

    <audio id="background_audio" autoplay="autoplay">
      <source src="static/audio/clip.ogg" type="audio/ogg" />
      <source src="static/audio/clip.mp3" type="audio/mpeg" />
    </audio> 

    <![if (!IE)|(gte IE 9)]>
    <a href="#" onclick="document.getElementById('background_audio').muted = true; return false">mute sound</a>
    <![endif]>

    <!--[if lt IE 9]>
    <bgsound id="background_snd" src="static/audio/clip.mp3" autostart="true" loop="1">
    <a href="#" onclick="document.all['background_snd'].src=''; return false">mute sound</a>
    <![endif]--> 

詳細はこちら: http://msdn.microsoft.com/en-us/library/ms537509(v=vs.85).aspx

于 2011-06-22T16:38:13.797 に答える