2017-07-24 42 views
0

我,當我試圖運行下面的HTML代碼歌廳錯誤Uncaught ReferenceError: Twitch is not defined加載抽搐播放器失敗,抽搐沒有定義

<div class="custom-box well" id="templateHolder"> 
    <script src="https://player.twitch.tv/js/embed/v1.js"></script> 
    <div id="testDivId"></div> 
    <script type="text/javascript"> 
     var options = {width:600,height:400,channel:"cookingForNoobs"}; 
     var player = new Twitch.Player("testDivId", options); 
     player.setVolume(0.5); 
    </script> 
</div> 

當我的jsfiddle它的工作原理,並沒有抱怨沒有發現運行Twitch。不過,作爲我的頁面的一部分,它的確如此。該頁面正確加載,除了這個div。也使用<iframe src="http://player.twitch.tv/?channel=cookingfornoobs&amp;muted=true" width="100%" height="800px"></iframe>將工作。我不確定是否有阻止加載Twitch播放器的呼叫。

有什麼我可以檢查,以確保其被正確處理?

作爲一個說明,它發生在Chrome和Firefox中,我可以在sources選項卡下看到player.twitch.tv js/embed v1.js文件。

+0

https://www.giantbomb.com/forums/bug-reporting-33/chrome-41-0 -2272-76-not-loading-embeded-twitch-pla-1767513/ –

+0

我檢查過,不幸的是它不是鉻問題,而且我沒有遇到網絡錯誤只有Twitch未定義的錯誤。我還看到了sources標籤中的twitch v1.js。 – Niru

+0

@Niru。當解釋新的Twitch.Player時,您的庫可能仍在加載。嘗試使用document.addEventListener(「DOMContentLoaded」或window.onload。 – karthick

回答

0

當解釋新的Twitch.Player時,您的庫可能仍在加載。

嘗試包裹內「DOMContentLoaded」或window.onload = function(){}抽搐初始化,如果你正在使用jQuery然後內$(document).ready(){}