html – Video not listed on youtube problems opening using iframe

Question:

I'm not able to open unlisted videos on youtube using the html iframe tag, the following error occurs:

Refused to display ' https://www.youtube.com ' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'

Does anyone know what it is? I tried using the video tag and it's not working either.

   <iframe width="420" height="315"
                            src="videodoyoutubenaolistado"></iframe>

Answer:

many famous websites end up blocking embedding in iframes because this allows the creation of malicious websites, so whenever you think about using an iframe for a website, see if it doesn't offer the option of embedding specific parts.

In the case of youtube, to avoid errors like this because it doesn't allow the whole page and to have to avoid going to get the embed on the site, you can change the url replacing watch?v= by embed/ this already makes only the window get caught from the video.

Example: https://www.youtube.com/watch?v=T-TwcmT6Rcw => https://www.youtube.com/embed/T-TwcmT6Rcw

you can see other functions here https://www.w3schools.com/HTML/html_youtube.asp

Scroll to Top