Hi there
I have a html page in which i have flash video and youtube video if borwser detect flash player the flash player vidoe run but if flash player not detect than it play youtube vidoe and the problem is that the iframe not open the youtube video it says Refused to display 'http://www.youtube.com/watch?v=VIDEO-IDfeature=youtu.be' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

"I have remove the video id because i don't want to show the video that why i remove the video id write VIDEO-ID"

I search for this error and find solution to add header at the top of the page but the probelm is that my page is .html and i cann't convert it into php i want to add this header with the help of javascript tell me what should i do now. why it give error of sameorigin means it open the main page inside the iframe

<?php
header('X-Frame-Options: GOFORIT');
?>

waiting for your reply

Dani AI

Generated

Good catch. The browser blocked your first attempt because you tried to iframe the YouTube watch page (?v=...), which sets X-Frame-Options: SAMEORIGIN so it cannot be embedded cross-origin. You cannot override another site’s X-Frame-Options from your HTML, JavaScript, or by sending a header from your page; only the site serving the framed page controls it. Also, valid directives are DENY or SAMEORIGIN (old ALLOW-FROM is obsolete) — not GOFORIT. The fix is exactly what you found: use the official embed endpoint. See MDN for the header behavior and allowed values, and YouTube’s docs for the embed URL format: X-Frame-Options header, YouTube embedded player parameters.

If you want a modern, copy-paste snippet with a lighter privacy touch and better UX, try this:

<iframe
  width="560" height="315"
  src="https://www.youtube-nocookie.com/embed/VIDEO_ID"
  title="YouTube video"
  loading="lazy"
  allow="autoplay; encrypted-media; picture-in-picture; web-share"
  allowfullscreen></iframe>

Privacy-enhanced mode (youtube-nocookie.com) reduces tracking until the viewer interacts, and is an option in YouTube’s embed dialog; it is functionally supported by YouTube Help: .

Two extra tips:

  • If you need JS control, add enablejsapi=1 and set origin=https://your-site.example as documented: YouTube embedded player parameters.
  • Some videos cannot be framed (for example, age‑restricted or when creators disable embedding) and will redirect to YouTube even with the correct embed URL: .
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.