I'm writing a tiny webpage whose purpose is to frame a few other pages, simply to consolidate them into a single browser window for ease of viewing. A few of the pages I'm trying to frame forbid being framed and throw a "Refused to display document because display forbidden by X-Frame-Options." error in Chrome. I understand that this is a security limitation (for good reason), and don't have access to change it.
Is there any alternative framing or non-framing method to display pages within a single window that won't get tripped up by the X-Frame-Options header?
If you are getting this error while trying to embed a Google Map in an
iframe
, you need to add&output=embed
to the source link.It's surprising that no one here has ever mentioned
Apache
server's settings (*.conf
files) or.htaccess
file itself as being a cause of this error. Search through your.htaccess
orApache
configuration files, making sure that you don't have the following set toDENY
:Header always set X-Frame-Options DENY
Changing it to
SAMEORIGIN
, makes things work as expected:Header always set X-Frame-Options SAMEORIGIN
If you are getting this error for a YouTube video, rather than using the full url use the embed url from the share options. It will look like
http://www.youtube.com/embed/eCfDxZxTBW4
You may also replace
watch?v=
withembed/
sohttp://www.youtube.com/watch?v=eCfDxZxTBW4
becomeshttp://www.youtube.com/embed/eCfDxZxTBW4
There is a plugin for Chrome, that drops that header entry (for personal use only):
https://chrome.google.com/webstore/detail/ignore-x-frame-headers/gleekbfjekiniecknbkamfmkohkpodhe/reviews
I'm not sure how relevant it is, but I built a work-around to this. On my site, I wanted to display link in a modal window that contained an iframe which loads the URL.
What I did is, I linked the click event of the link to this javascript function. All this does is make a request to a PHP file that checks the URL headers for X-FRAME-Options before deciding whether to load the URL within the modal window or to redirect.
Here's the function:
Here's the PHP file code that checks for it:
Hope this helps.
Not mentioned but can help in some instances: