真真js 改变embed src值 也就是js 给embed 赋值的方法
首先需要说明,直接修改是不行的,通常有以下方法:
1、直接用js把embed放在一div内 然后需要修改src的时候,我直接先将div内的内容清空,然后再用js将换了src的embed放在div内
代码如下
var tabv = document.getElementById("f_tabv"); var tabva = tabv.getElementsByTagName("a"); var tabcv = document.getElementById("f_tab_cv"); tabcv.innerHTML = '<EMBED src="abc.wmv" autostart="true" width="545" height="325" type="video/x-ms-asf"></EMBED>'; for(var i=0; i<tabva.length; i++){ tabva[i].onclick=function(){ var href1 = this.getAttribute("href"); var href2 = '<EMBED src="'+href1+'" autostart="true" width="545" height="325" type="video/x-ms-asf"></EMBED>'; tabcv.getElementsByTagName("embed")[0].style.display="none"; tabcv.innerHTML=""; tabcv.innerHTML=href2; for(i=0; i<tabva.length; i++){ tabva[i].className=''; } this.className = "act"; return false; } }2、在IE跟FF中,访问的方式可能会有差异。 以下是个例子。
- <object name="playerIE" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
- codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902"
- standby="Loading Microsoft Windows Media Player..." type="application/x-oleobject" width="220" height="40" >
- <param name="FileName" value="">
- <param name="autoStart" value="true">
- <param name="showControls" value="true">
- <!-- 自动重复 www.zzzyk.com -->
- <param name="loop" value="false">
- <embed id="playerFF" src="audio/niftyPlayer.swf?file=''" width="220" height="40" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> </embed>
- </object>
<object name="playerIE" classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902" standby="Loading Microsoft Windows Media Player..." type="application/x-oleobject" width="220" height="40" > <param name="FileName" value=""> <param name="autoStart" value="true"> <param name="showControls" value="true"> <!-- 自动重复 --> <param name="loop" value="false"> <embed id="playerFF" src="audio/niftyPlayer.swf?file=''" width="220" height="40" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> </embed> </object>
- function changeMusic(musicUrl){
- var media ;
- if(NOT_IE){
- media = document.getElementById("playerFF");
- media.src = player + '?file=' + musicUrl + '&as=1';
- }
- else{
- media = window.playerIE;
- media.setAttribute('FileName',musicUrl);
- }
- };