cross browser - javascript not working in chromeoperaIE but firefox is excellent! - Stack Overflow

I've got this code, working only in firefox.<script type="textjavascript">functio

I've got this code, working only in firefox.

 <script type="text/javascript">
    function setVideo(url){
        url = url.replace("watch?v=","v/","i");
        var movie = document.getElementById('movie');
        movie.setAttribute('src',url+"&hl=en&fs=1&");
        var param = document.getElementById('paramm');
        param.setAttribute('value',url+"&hl=en&fs=1&");
    }
</script>

<object width="425" height="344">
            <param name="movie" id="paramm"></param>
            <param name="allowFullScreen" value="true"></param>
            <param name="allowscriptaccess" value="always"></param>
            <embed id="movie" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344" src=""></embed>
        </object>

<a href="#" onclick="setVideo('')">example</a>

PLEASE help, I have no idea, it's such a simple script, why is it not working?? thanks

I've got this code, working only in firefox.

 <script type="text/javascript">
    function setVideo(url){
        url = url.replace("watch?v=","v/","i");
        var movie = document.getElementById('movie');
        movie.setAttribute('src',url+"&hl=en&fs=1&");
        var param = document.getElementById('paramm');
        param.setAttribute('value',url+"&hl=en&fs=1&");
    }
</script>

<object width="425" height="344">
            <param name="movie" id="paramm"></param>
            <param name="allowFullScreen" value="true"></param>
            <param name="allowscriptaccess" value="always"></param>
            <embed id="movie" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344" src=""></embed>
        </object>

<a href="#" onclick="setVideo('http://www.youtube./watch?v=3h1qQaRxY40')">example</a>

PLEASE help, I have no idea, it's such a simple script, why is it not working?? thanks

Share Improve this question asked Jun 30, 2010 at 11:46 AdrianaAdriana 8,64413 gold badges38 silver badges38 bronze badges 1
  • 1 What is this code supposed to do? What doesn't work? What error messages do you get? – Pekka Commented Jun 30, 2010 at 11:49
Add a ment  | 

4 Answers 4

Reset to default 6

You are trying to dynamically change the video source in an embed element. This is notoriously tricky and in fact needs a workaround for browsers other than Firefox.

This question seems to provide a solution: Dynamically change embedded video src in IE/Chrome (works in Firefox)

You didn't provide any error message, so it's hard to say what needs to be fixed ...

One thing I did notice is that you use non-standard syntax for the "replace" method.

See https://developer.mozilla/en/Core_JavaScript_1.5_Reference/Objects/String/replace for explanation and alternatives

You should probably use something like swfobject (http://code.google./p/swfobject) to embed the ENTIRE flash object when the setVideo function is called - don't just change the url. IE and chrome probably don't recognize the change.

Don't use setAttribute with value. It is known to cause problems.

function setVideo(url){
    url = url.replace("watch?v=","v/";
    var movie = document.getElementById('movie');
    movie.src = url+"&hl=en&fs=1&";
    var param = document.getElementById('paramm');
    param.value = url+"&hl=en&fs=1&";
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745234039a4617804.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信