Question

I've created a Custom Gadget in Youtube Brand Channel and it's hosted in SSL-complied server as of the requirement from Youtube.

However, if I access the channel via http, the postMessage() refuses to work, since it is called in the https server.

My code is like this:

var new_height = JSON.stringify({"height": height + "px"});
top.postMessage(new_height, location.protocol +"//www.youtube.com/");

The error is like this

Unable to post message to https://www.youtube.com. Recipient has origin http://www.youtube.com.

What can I do to fix this? Thanks

Was it helpful?

Solution

Make sure that your custom gadget is accessible with both protocols, http and https.

When user opens your channel with url https://youtube.com/[username], youtube will render your gadget in iframe with https, when user opens http://youtube.com/[username], youtube will render http version of your gadget.

Just make sure that you are not redirecting from http to https.

We made a gadget like this a couple of days ago with dynamic resizing and keeping in mind what i wrote earlier everything works on both protocols.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top