Javascript Youtube播放器Internet Explorer故障
我正在努力开发一款无铬Youtube播放器。上的控件链接在Firefox和Chrome上运行良好,但在Internet Explorer上不起作用。我如何解决这个问题?我认为这个问题和身份证有关,但也许我很困惑,因为我所做的一切都不能解决我的问题Javascript Youtube播放器Internet Explorer故障,javascript,internet-explorer,cross-browser,youtube-api,youtube-javascript-api,Javascript,Internet Explorer,Cross Browser,Youtube Api,Youtube Javascript Api,我正在努力开发一款无铬Youtube播放器。上的控件链接在Firefox和Chrome上运行良好,但在Internet Explorer上不起作用。我如何解决这个问题?我认为这个问题和身份证有关,但也许我很困惑,因为我所做的一切都不能解决我的问题 var ytplayer_playlist = [ ]; var ytplayer_playitem = 0; swfobject.addLoadEvent( ytplayer_render_player ); swfobject.ad
var ytplayer_playlist = [ ];
var ytplayer_playitem = 0;
swfobject.addLoadEvent( ytplayer_render_player );
swfobject.addLoadEvent( ytplayer_render_playlist );
function ytplayer_render_player( )
{
swfobject.embedSWF
(
'http://www.youtube.com/apiplayer?video_id='+ ytplayer_playlist[ ytplayer_playitem ] + '&enablejsapi=1&autoplay=1&loop=1&version=3&rel=0&fs=1&playerapiid=ytplayer',
'ytplayer',
'400',
'225',
'10',
null,
null,
{
allowScriptAccess: 'always',
allowFullScreen: 'true'
},
{
id: 'ytplayer'
}
);
}
function ytplayer_render_playlist( )
{
for ( var i = 0; i < ytplayer_playlist.length; i++ )
{
var img = document.createElement( "img" );
img.src = "http://img.youtube.com/vi/" + ytplayer_playlist[ i ] + "/default.jpg";
var a = document.createElement( "a" );
a.href = "#ytplayer";
//
// Thanks to some nice people who answered this question:
// http://stackoverflow.com/questions/1552941/variables-in-anonymous-functions-can-someone-explain-the-following
//
a.onclick = (
function( j )
{
return function( )
{
ytplayer_playitem = j;
ytplayer_playlazy( 1000 );
};
}
)( i );
a.appendChild( img );
document.getElementById( "ytplayer_div2" ).appendChild( a );
}
}
function ytplayer_playlazy( delay )
{
//
// Thanks to the anonymous person posted this tip:
// http://www.tipstrs.com/tip/1084/Static-variables-in-Javascript
//
if ( typeof ytplayer_playlazy.timeoutid != 'undefined' )
{
window.clearTimeout( ytplayer_playlazy.timeoutid );
}
ytplayer_playlazy.timeoutid = window.setTimeout( ytplayer_play, delay );
}
function ytplayer_play( )
{
var o = document.getElementById( 'ytplayer' );
if ( o )
{
o.loadVideoById( ytplayer_playlist[ ytplayer_playitem ] );
}
}
//
// Ready Handler (this function is called automatically by YouTube JavaScript Player when it is ready)
// * Sets up handler for other events
//
function onYouTubePlayerReady( playerid )
{
var o = document.getElementById( 'ytplayer' );
if ( o )
{
o.addEventListener( "onStateChange", "ytplayerOnStateChange" );
o.addEventListener( "onError", "ytplayerOnError" );
}
}
//
// State Change Handler
// * Sets up the video index variable
// * Calls the lazy play function
//
function ytplayerOnStateChange( state )
{
if ( state == 0 )
{
ytplayer_playitem += 1;
ytplayer_playitem %= ytplayer_playlist.length;
ytplayer_playlazy( 1000 );
}
}
//
// Error Handler
// * Sets up the video index variable
// * Calls the lazy play function
//
function ytplayerOnError( error )
{
if ( error )
{
ytplayer_playitem += 1;
ytplayer_playitem %= ytplayer_playlist.length;
ytplayer_playlazy( 1000 );
}
}
//
// Add items to the playlist one-by-one
//
ytplayer_playlist.push( 'tGvHNNOLnCk' );
ytplayer_playlist.push( '_-8IufkbuD0' );
ytplayer_playlist.push( 'wvsboPUjrGc' );
ytplayer_playlist.push( '8To-6VIJZRE' );
ytplayer_playlist.push( '8pdkEJ0nFBg' );
function play() {
if (ytplayer) {
ytplayer.playVideo();
}
}
function pause() {
if (ytplayer) {
ytplayer.pauseVideo();
}
}
function stop() {
if (ytplayer) {
ytplayer.stopVideo();
}
}
var ytplayer_playlist=[];
var ytplayer_playitem=0;
swfobject.addLoadEvent(ytplayer\u render\u player);
swfobject.addLoadEvent(ytplayer\u render\u播放列表);
函数ytplayer\u render\u player()
{
swfobject.embeddeswf
(
'http://www.youtube.com/apiplayer?video_id=“+ytplayer\u playlist[ytplayer\u playitem]+”&enablejsapi=1&autoplay=1&loop=1&version=3&rel=0&fs=1&playerapiid=ytplayer”,
“ytplayer”,
'400',
'225',
'10',
无效的
无效的
{
allowScriptAccess:“始终”,
allowFullScreen:'真'
},
{
id:'ytplayer'
}
);
}
函数ytplayer\u render\u playlist()
{
对于(var i=0;i
替换这些调用(调用对象ytplayer
):
以下是:
document.getElementById('ytplayer').pauseVideo();
// ...
Internet Explorer将ytplayer
对象视为HTMLCollection:
通过明确选择元素,您可以调用函数。替换这些调用(调用对象ytplayer
):
以下是:
document.getElementById('ytplayer').pauseVideo();
// ...
Internet Explorer将ytplayer
对象视为HTMLCollection:
通过明确地选择元素,您可以调用函数。到底什么不起作用?是否有任何错误消息或控制台日志?播放暂停停止按钮不工作。没有错误我得到了一堆错误:你能调试一下,看看是什么类型的对象
ytplayer
吗?到底是什么不起作用?是否有任何错误消息或控制台日志?播放暂停停止按钮不工作。没有错误我有一大堆错误:你能调试一下,看看是什么类型的对象ytplayer
吗?谢谢。你知道一个学习dom和firebug的好来源吗:)@Laura嗯,我现在可以发布一些我找到的。它们可能更老,但仍然是准确的:。谢谢你。你太棒了,谢谢。你知道一个学习dom和firebug的好来源吗:)@Laura嗯,我现在可以发布一些我找到的。它们可能更老,但仍然是准确的:。谢谢你。你太棒了。