Javascript – How to set ‘X-Frame-Options’ on iframe


If I create an iframe like this:

var dialog = $('<div id="' + dialogId + '" align="center"><iframe id="' + frameId + '" src="' + url + '" width="100%" frameborder="0" height="'+frameHeightForIe8+'" data-ssotoken="' + token + '"></iframe></div>').dialog({

How can I fix the error:

Refused to display '' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

with JavaScript?

Best Answer

You can't set X-Frame-Options on the iframe. That is a response header set by the domain from which you are requesting the resource ( in your example). They have set the header to SAMEORIGIN in this case, which means that they have disallowed loading of the resource in an iframe outside of their domain. For more information see The X-Frame-Options response header on MDN.

A quick inspection of the headers (shown here in Chrome developer tools) reveals the X-Frame-Options value returned from the host.

enter image description here

Related Question