即使使用document.getElementById('xyz'),也无法控制Youtube嵌入。playVideo() - 不是函数吗? [英] Can't control Youtube embed even with document.getElementById('xyz').playVideo() - not a function?
问题描述
如果我用< body>创建一个HTML文件,是:
< object id =o1width =480height =295>
< param name =movie
value =http://www.youtube.com/v/qCTLCNmnlKU&hl=zh_TW&fs=1&enablejsapi=1&>
< / param>
< param name =allowscriptaccessvalue =always>< / param>
< embed id =e1
src =http://www.youtube.com/v/qCTLCNmnlKU&hl=zh_CN&fs=1&enablejsapi=1&
type =application / x-shockwave-flash
allowcriptaccess =alwaysallowfullscreen =truewidth =480height =295>
< / embed>
< / object>
甚至当我试图做:
//我得到一个对象。好极了。
document.getElementById('e1');
//这将产生... playVideo不是一个函数
document.getElementById('e1')。playVideo();
帮助!我究竟做错了什么?谢谢。
好的,下面是API页面中一小段文字的答案: http://code.google.com/apis/youtube/js_api_reference.html
$ b
注意:要测试这些调用,必须让您的文件在网络服务器上运行,因为Flash播放器会限制本地文件和互联网。
为了让我继续在我的Mac笔记本电脑上开发,我做了以下工作: p>
-
编辑我的 / etc / hosts 文件以包含一个条目回到我的本地主机:
127.0.0.1 testhost.com
-
编辑我的 /etc/apache2/httpd.conf 文件来添加一个指向我的开发目录的虚拟主机条目:
< VirtualHost *:80>
ServerName testhost.com
DocumentRoot / Users / amy / flashproj
< Directory / Users / amy / flashproj>
AllowOverride all
选项MultiViews索引FollowSymLinks
允许全部
< / Directory>
< / VirtualHost>
-
重新启动的Apache:
<$ p $ b $sudo apachectl restart
-
回到我自己的localhost通过我的新的虚拟服务器:
http://testhost.com
瞧。现在完全有效。我可以查询播放器的页面:
document.getElementById('e1'); // OK
document.getElementById('e1')。playVideo(); // 好!
Whew!不需要 onYouTubePlayerReady()!
OK, I'm stuck and I don't know what's wrong even after following Google's docs and reading suggestions here on Stackoverflow. Why can't I control Youtube embeds in my web page?
If I create an HTML file with the <body> being:
<object id="o1" width="480" height="295">
<param name="movie"
value="http://www.youtube.com/v/qCTLCNmnlKU&hl=en_US&fs=1&enablejsapi=1&">
</param>
<param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed id="e1"
src="http://www.youtube.com/v/qCTLCNmnlKU&hl=en_US&fs=1&enablejsapi=1&"
type="application/x-shockwave-flash"
allowscriptaccess="always" allowfullscreen="true" width="480" height="295">
</embed>
</object>
Even when I attempt to do:
// I get an object. Yay.
document.getElementById('e1');
// This generates "...playVideo is not a function"
document.getElementById('e1').playVideo();
Help! What am I doing wrong? Thanks.
OK, so here's the answer found in one tiny line of text on the API page: http://code.google.com/apis/youtube/js_api_reference.html
"Note: To test any of these calls, you must have your file running on a webserver, as the Flash player restricts calls between local files and the internet."
So to allow me to continue to develop on my Mac laptop I did the following:
Edited my /etc/hosts file to include an entry back to my localhost:
127.0.0.1 testhost.com
Edited my /etc/apache2/httpd.conf file to add a virtual host entry pointing back to my development directory:
<VirtualHost *:80> ServerName testhost.com DocumentRoot /Users/amy/flashproj <Directory /Users/amy/flashproj> AllowOverride all Options MultiViews Indexes FollowSymLinks Allow from All </Directory> </VirtualHost>
Restarted Apache:
sudo apachectl restart
Browsed back to my own localhost via my new virtual server:
http://testhost.com
Voila. That totally works now. I can query the page for the player:
document.getElementById('e1'); // OK
document.getElementById('e1').playVideo(); // OK!
Whew! No onYouTubePlayerReady() required either!
这篇关于即使使用document.getElementById('xyz'),也无法控制Youtube嵌入。playVideo() - 不是函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!