Embedding youtube video “Refused to display document because display forbidden by X-Frame-Options”

I'm trying to embed a youtube video on to my page once the user gives the link to the video.

<iframe width=\'560\' height=\'315\' src='http://www.youtube.com/watch?v=<video id>&amp;output=embed' frameborder=\'0\' allowfullscreen></iframe>

But when I try to add this I get this error. After inspecting the page in chrome, I see this error in the console tab

"Refused to display document because of the display is forbidden by X-Frame-Options"

I'm not able to see the video even in IE and Firefox also

I even tried adding the

 header('X-Frame-Options:Allow-From http://www.youtube.com'); 
 &amp;output=embed to the url

After reading certain solutions in other posts.

But I still get the same error.

I also see that the youtube has the method of object embedding to show the video, but already youtube has made that as old method of embedding the video. So I want to use the new iframe method of embedding the video on to my page.

Problem is seen in

  • Firefox 11
  • Chrome 18.0
  • IE 8

Anybody faced this problem?



The page you're setting as the source of the iframe (the Youtube /watch page) doesn't want to be embedded in your page. You cannot force it to let you do that.

The correct URL to embed is of the form:


When you copy a video link off YouTube: "https://www.youtube.com/watch?v=Fva3fgKmu3o"

-Replace 'watch' with /embed/

-Remove '?v='

Final Example: "https://www.youtube.com/embed/Fva3fgKmu3o"


Replace the keyword watch?v= with embed and change the live URL something like this:-

$url= str_replace('watch?v=','embed/', $url_string);

And then embed it in the iframe

<iframe id="player" type="text/html" width="640" height="390" src="{{ $url }}" frameborder="0"></iframe>

TL;DR: You may need to delete your cookies.

If it still doesn't work with either /v or /embed, the issue may be on your client, because of malformatted cookies. You can also see this error because of a 400 HTTP ERROR on most or every YouTube pages.

To fix this issue you'll have to delete YouTube cookies:

In Chrome, enter chrome://settings/siteData in the address bar, and enter youtube in the Search cookies box.

Next, you will see two groups of cookies for youtube, you could remove all, OR if you click the little arrow, you will be able to see the individual cookie names, and could just delete specific ones like all the gsScrollPos-####.

Sources of this answer and more details can be found on this Reddit thread.


Check the official doc at Embed a video or playlist from support.google.com/youtube

<iframe width="560" height="315"
frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

Check more tips, tricks about youtube


Add this to your HTML code don't copy the exact video link but right click and copy embed code and paste in src" "

<div class="example">
 src="<iframe width="853" height="480" src="https://www.youtube.com/embed/jH0Q8NOsIR8" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>" </iframe>


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.