在IE / Chrome中动态更改嵌入式视频src(适用于Firefox) [英] Dynamically change embedded video src in IE/Chrome (works in Firefox)

查看:154
本文介绍了在IE / Chrome中动态更改嵌入式视频src(适用于Firefox)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试动态更改页面上的嵌入视频。它在Firefox中工作但由于某种原因它不适用于IE和Chrome(奇怪的组合)。这是HTML:

I'm trying to dynamically change an embedded video on a page. It's working in Firefox but for some reason it's not working in IE and Chrome (strange combination). Here's the HTML:

   <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>

这是我的javascript代码。点击链接更改视频:

And here's my javascript code. A link is clicked to change the video:

        $("#video a").click(
            function() {
                var videoAddress = $(this).attr("href");
                $("#embeddedPlayer").attr("src", videoAddress);
                return false; // stop the default link so it just reloads in the video player
            }
        );

就像我说的视频在Firefox中完美变化但在IE和Chrome中没有任何反应。任何想法?

Like I said the videos are changing perfectly in Firefox but in IE and Chrome nothing happens. Any ideas?

推荐答案

最后想出了适用于IE,Firefox和Chrome的东西。

Finally figured out something that works in IE, Firefox, and Chrome.

这样做似乎有点不寻常,但它适用于IE8 / Firefox / Chrome,所以对我来说听起来不错。

It seems a little unusual to do it this way but it works in IE8/Firefox/Chrome so it sounds good to me.

$("#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
            }
);

这篇关于在IE / Chrome中动态更改嵌入式视频src(适用于Firefox)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆