IFrame request cancelled

2019-05-03 19:30发布

问题:

This example to load a url in an iframe works. However when I change url to something like http://www.yahoo.com the iframe doesn't load antyhing

Here is an example side by side.

In Network tab of developer tools for Chrome, I see that request to Yahoo was cancelled. In FF it doesn't give any errors, just doesn't return any content. IE9 gives a message that It cannot display this content.

This happens in Chrome, FF and IE9 (I haven't tested previous versions of IE).

回答1:

That is because Yahoo itself prevents this from happening.

It has been noted here: https://stackoverflow.com/a/9013722/476786

To see for yourself, try setting the source to http://www.google.com/ which won't work as well, but then try http://www.bbc.co.uk/ and that will work.

Possibly works as described here: https://stackoverflow.com/a/2896705/476786 using X-FRAME-OPTIONS



回答2:

If the site hosting the webpage forces the use of a secure HTTPS connection, some browsers (chrome for sure) will require that all network resources use HTTPS as well.

Basically if your site forces HTTPS, try setting src="https://yahoo.com"

This won't solve OP's answer directly due to it being a limitation of Yahoo itself, but other people viewing this page might be experiencing this issue as a result of this (I was).



标签: html iframe