2016-11-05 90 views
0

我想在本地主機中包含一個YouTube訂閱按鈕,它似乎並不工作,而在JSfiddle中它工作得很好。難道我做錯了什麼?我在本地主機上使用代碼https://developers.google.com/youtube/youtube_subscribe_buttonYoutube訂閱按鈕不顯示

我的代碼:

<!DOCTYPE html> 
<html> 
<head> 
    <title>Testing a YouTube button</title> 
    <script src="https://apis.google.com/js/platform.js"></script> 
</head> 
<body> 
    <div class="g-ytsubscribe" data-channelid="UCWTfbcQsyNLv1ZLsZrhVW2w" data-layout="full" data-count="default"></div> 
</body> 
</html> 

JSFiddle example

謝謝!

回答

0

當我在http://localhost上測試它時,它工作正常,但當我使用file:// URL測試它時,它失敗。

控制檯報告:

CB = gapi.loaded_0:45無法執行 '的postMessage' 上 'DOMWindow':提供的目標來源( '文件://')不匹配收件人窗口原點('null')。

該腳本僅適用於加載HTTP(S)的網頁。不要嘗試在file:網址上使用它(並始終查看控制檯中的錯誤消息!)。

+0

偉大的昆汀,感謝您的信息。 – Andrew