2010-02-04 22 views
5

मैं जावास्क्रिप्ट के साथ एक एम्बेडेड यूट्यूब क्रोमलेस प्लेयर को नियंत्रित कर रहा हूं, और मैं इसे कभी-कभी डिस्प्ले सेट करके छिपाना चाहता हूं: none। हालांकि, जब मैं खिलाड़ी को फिर से दिखाता हूं, तो यह इसके यूट्यूब तरीकों को खो देता है।छिपी हुई यूट्यूब प्लेयर अपनी विधियों को खो देता है

उदाहरण के लिए:

<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> 

showPlayer के बाद hidePlayer कॉलिंग playVideo फोन पर इस त्रुटि देता है:

Uncaught TypeError: Object #<an HTMLObjectElement> has no method 'playVideo' 

एकमात्र समाधान मैं पा सकते हैं दृश्यता का उपयोग करना है: छिपा हुआ है, लेकिन वह यह है कि मेरे पेज लेआउट के साथ गड़बड़ाना। वहाँ कोई अन्य समाधान?

उत्तर

0

मेरे साथ यह मेरे उपयोगकर्ताक्रिप्ट में भी हुआ है। आप इसे पूरी तरह छिपाने के बजाय इसे 1x1 पीएक्स बनाने की कोशिश कर सकते हैं।

यह एक बहुत ही परेशान मुद्दा है, और यह समझ में नहीं आता कि ऐसा क्यों होता है।

0

दोनों प्रदर्शन: कोई भी और दृश्यता: छुपा खिलाड़ी को फिर से लोड करेगा, लेकिन आप इसे वीडियो प्लेयर को ओवरफ्लो के साथ एक div में लपेटकर सीएसएस के माध्यम से हल कर सकते हैं: छुपा हुआ।

HTML:

<div id="ytwrapper"> 
    <div id="ytplayer"> 
    </div> 
</div> 

सीएसएस:

#ytwrapper { overflow: hidden; } 

जे एस:

function hidePlayer() { 
    player.pauseVideo(); 
    player.style.marginLeft = "50000px"; 
} 

function showPlayer() { 
    player.style.marginLeft = "0px"; 
    player.playVideo(); 
} 
संबंधित मुद्दे