Andrew Andrew - 8 months ago 54
HTML Question

Youtube subscribe button not showing

I am trying to include a YouTube subscribe button in localhost and it does not seem to work, while in JSfiddle it works perfectly fine. Am I doing something wrong? I am using code from

My code on localhost:

<!DOCTYPE html>
<title>Testing a YouTube button</title>
<script src=""></script>
<div class="g-ytsubscribe" data-channelid="UCWTfbcQsyNLv1ZLsZrhVW2w" data-layout="full" data-count="default"></div>

JSFiddle example



It works fine when I test it on http://localhost, but it fails when I test it using a file:// URL.

The console reports:

cb=gapi.loaded_0:45 Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null').

The script only works when you load the webpage of HTTP(S). Don't try to use it on file: URLs (and always look at the console for error messages!).