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 https://developers.google.com/youtube/youtube_subscribe_button
My code on localhost:
<!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>
Thanks!
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!).