我正在用javascript控制嵌入式YouTube无铬播放器,我想通过设置display:none来偶尔隐藏它。但是,当我再次向玩家展示时,它会丢失其YouTube方法。隐藏的YouTube播放器失去其方法
例如:
<script>
swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&playerapiid=player",
"player", "425", "356", "8", null, null,
{allowScriptAccess: "always"}, {id: 'player'}
);
var player = null;
function onYouTubePlayerReady(playerId) {
player = document.getElementById(playerId);
player.addEventListener('onStateChange', 'playerStateChanged');
}
function hidePlayer() {
player.pauseVideo();
player.style.display = 'none';
}
function showPlayer() {
player.style.display = 'block';
player.playVideo();
}
</script>
<a href="#" onClick="hidePlayer();">hide</a>
<a href="#" onClick="showPlayer();">show</a>
<div id="player"></div>
调用hidePlayer其次showPlayer提供了有关的playVideo调用此错误:
Uncaught TypeError: Object #<an HTMLObjectElement> has no method 'playVideo'
我能找到的唯一解决方案是使用visibility:hidden的,但是这是搞乱我的页面布局。那里有其他解决方案吗?