Html iframes not working


#1

I am learning how to do iframes. They don’t appear to working online. The frame is created, but the content does not load.

However, if I download the workspace and run from my machine, everything works correctly without me having to make any changes to the code.

Could someone please advise me as to what is wrong and how I can correct this.


#2

Can you please post your code here, so that we can try to figure out why? Also, if you are running it inside the preview inside c9, please open it in a new tab and check, as the preview isn’t always reliable.


#3

We have determined that the iframe coding works if the src is to an
internal page within my own site. However, if I change the src to an
external website such as http://www.cnn.com/, the iframe does not load
properly.

If we download the project, both internal and external pages work within
the iframe coding. So we assume the coding is right.

But here it is anyways:

not work:

<iframe src="http://www.cnn.com/" height="500" width="850">
</iframe>

does work:

<iframe src="hello-world.html" height="500" width="850">
</iframe>

#4

This is likely due to the server you are using (Apache or the like) setting the X-Frame-Options header. This specifies what can be loaded into IFrames, and it’s likely set to SAMEORIGIN right now. Do a quick google search and you’ll find some great articles on what it does like this MDN one.