youtube embedd

i would like the video link to play directly on youtube. - directly plays in youtube.
<iframe src="" allowfullscreen></iframe> - this does not play on the page as its blocked.
would like to go to youtube directly if video thumbnail is clicked as per the instructions given on the video.
what is the code solution?
page :
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason C. LevineDon't talk to me.Commented:
The videos are blocked because the owner of the video doesn't want it embedded.  If you are the owner, turn on "Allow Embedding" in each video.

If you are not the owner, then you are out of luck.
Dave BaldwinFixer of ProblemsCommented:
Since the video comes up and says it is blocked, I think you should believe them.
Alexandre SimõesManager / Technology SpecialistCommented:
Hi mate, this is possible using the API

Here's a simple demo I've done based on the sample code on the API page.
IMPORTANT: To make it work in plunker you need to detach the preview pane by clicking in the top right blue button.

In my example, I chose to ask the user what to do.
Just change that logic to reflect your needs.

The basic idea is to catch the onError event and identify if the error is 101 or 150.
See the API reference to understand what these and other error codes mean.

Read the API Reference to understand how it works.
var videoId = '0JegviRvcEw';

// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');

tag.src = "";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

// 3. This function creates an <iframe> (and YouTube player)
//    after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
  player = new YT.Player('player', {
    height: '390',
    width: '640',
    videoId: videoId,
    events: {
      'onReady': onPlayerReady,
      'onError': onPlayerError,
      'onStateChange': onPlayerStateChange

// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {;

// 5. The API calls this function when the player's state changes.
//    The function indicates that when playing a video (state=1),
//    the player should play for six seconds and then stop.
var done = false;
function onPlayerError(event){
  // check here for more info:
  var contentEmbededBlockedErrorCodes = [101, 150];
  if(contentEmbededBlockedErrorCodes.indexOf( >= 0){
    // do whatever you want here
    if(confirm('Your video is not available in embeded mode.\n\nDo you want to open it directly on YouTube?')){
      window.location.href = '' + videoId;
function onPlayerStateChange(event) {
  if ( == YT.PlayerState.PLAYING && !done) {
    setTimeout(stopVideo, 6000);
    done = true;
function stopVideo() {

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.