How do I display / hide content on a page based on the site's "HTTP status"?


I have the following problem ...

Scenario: A site with HTML-only page delivery (we can not use a server-side language).

We do a YouTube embed video, but some companies, as we know, block their employees' access to social networks. It happens that in the frame of youtube (embed) the content message appears blocked.

One of the possible solutions would be to identify the HTTP status and if you return 200, we display the frame with the Youtube embed. If not, hide the frame and only the background image is displayed, and the user error that does not have access is not displayed.

Is it possible to do this only with the use of javascript?

asked by anonymous 30.04.2014 / 19:59

1 answer


Since you're using a frame embed, using the javascript API to control the Player, then probably < in> callback onYouTubeIframeAPIReady() is never invoked with the video blocked.

I do not know the behavior of the API in this situation, so I can not give a definitive answer, but I imagine the following scenario to reach its object:

  • Initially, show only a loading image of the video.
  • If the callback method is called, we assume that iframe has initialized correctly, then show the video.
  • If, after a certain time ( timeout ), the event is not called, then show the final image by replacing the video.
  • 30.04.2014 / 21:16