xRobot xRobot - 1 month ago 10
HTML Question

iFrame doesn't work in this case?

I need a way to display some websites in an iframe.
But it doesn't work, why ?

<iframe src="https://www.msn.com/it-it/" ></iframe>
<iframe src="http://www.lastampa.it/" ></iframe>


As you can see here, only the iframe on the right does work:

http://codepen.io/anon/pen/EgGrjQ

Answer

You can not do that because the site won't allow it. If you have a look in console you will see "Refused to display 'https://www.msn.com/it-it/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'"

This means you won't be able to display https://www.msn.com/it-it/ in an iframe if the iframe is not in the same domain.

More details here https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options

Comments