IE FireFox safari下javascript操作embed標籤

來源:互聯網
上載者:User

這段時間太忙了,都沒時間我工作心得寫下來了,今天抽個時間把前兩天工作中碰到的一些很棘手的問題以及解決的方法:

問題描述:
embed標籤接受到直播流以後在IE下可以通過play()和pause()方法得到很好的播放/暫停控制,但在FireFox和safari 去無能為力,在Firefox和safari下可以正常的播放(在safari需要裝media外掛程式),但是就是通過play() 和pause()無法控制它的播放和暫停,問題的根源是Firefox和Safari不能很好的支援embed標籤。就這個一個小問題耗了好多時間,惱火啊!

解決方案:

也許會有更好的方法,我的解決方案是這樣的:當點擊暫停按鈕的時候,首先去判斷瀏覽器的類型,如果不是IE就直接把Embed這個標籤從DOM中remove掉,單點播放按鈕的時候再把Embed標籤動態載入到DOM中。就這樣,問題解決了。
相關代碼如下:
//包含Embed標籤的層
<div id="radio_container"><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/mediaPlayer/" id="player" src="http://pub.qmoon.net:8009/911pop" name="player" width="0" height="0" volume="100"> </embed></div>    

//暫訂
var trnode=document.getElementById("player");
trnode.parentNode.removeChild(trnode);

//播放
var container=document.getElementById("radio_container");

var str="<embed type=/"application/x-mplayer2/" pluginspage=/"http://www.microsoft.com/windows/mediaPlayer//" id=/"player/" src=/"http://直播流地址/" name=/"player/" width=/"0/" height=/"0/" volume=/"100/">";

container.innerHTML+=str;

哈哈,希望能對部分朋友有所協助哈^-^

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.