Javascript 在IE/Chrome中动态更改嵌入式视频src(适用于Firefox)
我正在尝试动态更改页面上的嵌入式视频。它可以在Firefox中使用,但由于某些原因,它不能在IE和Chrome(奇怪的组合)中使用。以下是HTML:Javascript 在IE/Chrome中动态更改嵌入式视频src(适用于Firefox),javascript,jquery,video,embed,Javascript,Jquery,Video,Embed,我正在尝试动态更改页面上的嵌入式视频。它可以在Firefox中使用,但由于某些原因,它不能在IE和Chrome(奇怪的组合)中使用。以下是HTML: <object id="viewer" width="575" height="344"> <param name="wmode" value="transparent" /> <param name="movie" value="http://www.youtube.com/v/
<object id="viewer" width="575" height="344">
<param name="wmode" value="transparent" />
<param name="movie" value="http://www.youtube.com/v/Lmn94kn08Lw&hl=en&fs=1&color1=0x006699&color2=0x54abd6&rel=0" />
<param name="allowFullScreen" value="true" />
<embed id="embeddedPlayer" src="http://www.youtube.com/v/Lmn94kn08Lw&hl=en&fs=1&color1=0x006699&color2=0x54abd6&rel=0" type="application/x-shockwave-flash" allowfullscreen="true" width="575" height="344" wmode="transparent"></embed>
</object>
就像我说的,Firefox中的视频变化非常完美,但IE和Chrome中什么都没发生。有什么想法吗?标签用于向后兼容。请尝试更改参数值
$("#viewer param[name=movie]").attr("value", videoAddress);
终于找到了在IE、Firefox和Chrome中都能使用的东西 这样做似乎有点不寻常,但它在IE8/Firefox/Chrome中工作,所以听起来不错
$("#video a").click(
function() {
var videoAddress = $(this).attr("href");
$("#media-active").html(" ");
$("#media-active").html('<object id="viewer" width="575" height="344"><param name="wmode" value="transparent" />' +
'<param name="movie" value="' + videoAddress + '" /><param name="allowFullScreen" value="true" />' +
'<embed id="embeddedPlayer" src="' + videoAddress + '" type="application/x-shockwave-flash" allowfullscreen="true" width="575" height="344" wmode="transparent"></embed></object>');
return false; // stop the default link so it just reloads in the video player
}
);
$(“#视频a”)。单击(
函数(){
var videoAddress=$(this.attr(“href”);
$(“#媒体活动”).html(“”);
$(“#媒体活动”).html(“”+
'' +
'');
return false;//停止默认链接,使其重新加载到视频播放器中
}
);
几天前有人问过这个问题,IIRC建议使用SWFPlayer
JS库,正是因为这个原因。我尝试过这个,但不幸的是没有什么不同。谢谢你发布这个,我花了一段时间想弄清楚怎么做,除了我用的是音频src。我没有看到有人说要使用.html()@macca1。非常聪明的代码。我尝试在我的网站中使用您的代码,我尝试在我的网站中创建视频库。不幸的是,我不能让它工作。您提到的media active
,是div
?还是对象
?也许这对我有帮助。谢谢
$("#video a").click(
function() {
var videoAddress = $(this).attr("href");
$("#media-active").html(" ");
$("#media-active").html('<object id="viewer" width="575" height="344"><param name="wmode" value="transparent" />' +
'<param name="movie" value="' + videoAddress + '" /><param name="allowFullScreen" value="true" />' +
'<embed id="embeddedPlayer" src="' + videoAddress + '" type="application/x-shockwave-flash" allowfullscreen="true" width="575" height="344" wmode="transparent"></embed></object>');
return false; // stop the default link so it just reloads in the video player
}
);