在本地HTML文件中嵌入YouTube视频无法工作(使用file:// URL)

3
为什么在本地主机上从YouTube嵌入视频可以正常工作,但当视频在C盘时却不能正常工作?
eg: http://localhost/test/test.html                (embedded video works ) 

file:///C:/Users/AUser%20name/Desktop/test/test.html  (embedded video does not work)

这是我嵌入视频的代码片段。
<object width="560" height="315"><param name="movie" value="//www.youtube.com/v/0l-
7IGRsORI?hl=en_US&amp;version=3"></param><param name="allowFullScreen" value="true">
</param><param name="allowscriptaccess" value="always"></param><embed
src="//www.youtube.com/v/0l-7IGRsORI?hl=en_US&amp;version=3" type="application/x-
shockwave-flash" width="560" height="315" allowscriptaccess="always"
allowfullscreen="true"></embed></object>
1个回答

7
因为你在URL开头使用了//,这意味着你继承了当前所用的协议。在你的主机上,它是http://(好的),但在你的C盘上,它是file://(不好的)。
因此,只需使用http://而不是//:
<object width="560" height="315">
    <!-- See: value="http://.. -->
    <param name="movie" value="http://www.youtube.com/v/0l-7IGRsORI?hl=en_US&amp;version=3"></param>
    <param name="allowFullScreen" value="true"></param>
    <param name="allowscriptaccess" value="always"></param>

    <!-- See: src="http://.. -->
    <embed src="http://www.youtube.com/v/0l-7IGRsORI?hl=en_US&amp;version=3" type="application/x-shockwave-flash" width="560" height="315" allowscriptaccess="always" allowfullscreen="true"></embed>
</object>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接