2010-06-30 77 views
0

我有这个代码,只能在firefox中工作。JavaScript不工作在铬/歌剧/ IE浏览器,但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.com/watch?v=3h1qQaRxY40')">example</a> 

请帮忙,我不知道,这是一个这么简单的脚本,为什么它不工作? 谢谢

+1

这段代码应该做什么?什么不行?你得到什么错误信息? – 2010-06-30 11:49:16

回答

3

你没有提供任何错误信息,所以很难说需要修正什么...

有一件事我没有注意到的是,对于“替换”方法使用非标准语法。

https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/String/replace的解释和替代

+0

...或者查看所有JavaScript引擎所基于的[String.replace的ECMAScript规范](http://ecma262-5.com/ELS5_Section_15.htm#Section_15.5.4.11)。 – 2010-06-30 12:01:25

+0

对不起,在其他浏览器比firefox的视频是空白..没有视频 – Adriana 2010-06-30 12:43:31

2

你或许应该使用类似的SWFObject(http://code.google.com/p/swfobject)嵌入在setVideo函数被调用整个Flash对象 - 不只是改变的URL。 IE和chrome可能不会识别这种变化。

1

请勿将setAttribute与值一起使用。它被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&"; 
} 
相关问题