How to view/hide content from a page according to the "HTTP status" of the site?

Asked

Viewed 279 times

8

I have the following problem...

Scenario: A site with HTML-only pages (we cannot use a server-side language).

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

One of the possible solutions would be to identify the HTTP status and if it returns 200, we display the frame with Youtube embed. Otherwise, we hide the frame and only the background image is displayed, no error is displayed for the user who has no access.

It is possible to do this only with the use of javascript?

  • 2

    I believe you would have to request the video via Ajax.

  • 1

    Take a look at this here, I think the solution is there: http://www.newmediacampaigns.com/blog/lazyytjs-a-jquery-plugin-to-lazy-load-youtube-videos

1 answer

1


Since you are using an Embed frame, through the API javascript, to control the Player, then probably the callback onYouTubeIframeAPIReady() is never invoked with the video locked.

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

  1. Initially, show only a video upload image.
  2. If the method callback is called, we take as a basis that the iframe initialized correctly, then show the video .
  3. If, after a certain time (timeout), the event is not called, then show the final image replacing the video.
  • The question of including the image initially, we also considered, but you complemented it with an item we didn’t talk about. Anyway, it already gave a "light"... :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.