Embed a video on YouTube "Refused to display the document because the display is prohibited using X-Frame-Options"

I try to embed a YouTube video on my page as soon as the user gives a 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 checking the page in chrome, I see this error on the console tab

"Failure to display the document due to the fact that the display is prohibited by X-Frame-Options"

I can’t watch videos even in IE and Firefox as well

I even tried to add

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

After reading certain decisions in other posts.

But I still get the same error.

I also see that youtube has a method of embedding objects for showing videos, but youtube already did this as an old method of embedding videos. So I want to use the new iframe method to embed the video in my page.

The problem is visible in

  • Firefox 11
  • Chrome 18.0
  • IE 8

Has anyone encountered this problem?

+56
javascript html security php
Mar 29 '12 at 23:15
source share
5 answers

The page that you set as the iframe source (Youtube /watch page) does not want to be embedded in your page. You cannot make it do it.

The correct URL to insert is:

 http://www.youtube.com/embed/oHg5SJYRHA0 
+176
Mar 29 '12 at 23:32
source share

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

-Replace 'watch' with / embed /

-Remove '? V = '

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

+1
Feb 07 '19 at 3:22
source share

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




If it still does not work with /v or /embed , the problem may be in your client due to incorrectly formatted cookies. You may also see this error due to an HTTP 400 error on most or every YouTube page.

To solve this problem, you need to delete YouTube cookies:

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

Next, you will see two groups of cookies for YouTube, you can delete everything, or, if you click on the small arrow, you can see the individual gsScrollPos-#### cookies and just delete the specific ones, like all gsScrollPos-#### .

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

0
Nov 02 '18 at 19:18
source share

Replace the watch keyword with a built-in one and change the actual URL to something like this:

 $url_string="https://www.youtube.com/watch?v=H1pTkatn6sI"; $url= str_replace('watch?v=','embed/', $url_string); 

And then paste it in iframe

 <iframe id="player" type="text/html" width="640" height="390" src="{{ $url }}" frameborder="0"></iframe> 
0
Jul 17 '19 at 7:54
source share

Check the white paper at the Insert video or playlist page from support.google.com/youtube

 <iframe width="560" height="315" src="https://www.youtube.com/embed/videoseries?list=PLx0sYbCqOb8TBPRdmBHs5Iftvv9TPboYG" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> 

Check out more tips, tricks about YouTube

-one
Jun 25 '19 at 22:47
source share



All Articles