2017-07-29 96 views
-1

我想用Iframe用法找出约束。iframe不显示任何主要网站的东西

以下线路工作正常,我可以看到在iframe中的内容:

<iframe src="https://www.w3schools.com/" height="500" width="500"></iframe> 

<iframe src="https://www.w3.org/" height="500" width="500"></iframe> 

但这些线路不能正常工作:

<iframe src="https://www.microsoft.com/en-gb/" height="500" width="500"></iframe> 

<iframe src="https://www.google.com/" height="500" width="500"></iframe> 

如何确定哪些网站可以在iframe得到支持和哪些不是?有没有办法在iframe中找不到它?我想在用户输入URL来通知他web site is not supported in iframe时显示一条消息。

+0

的可能的复制错误的图像[如何显示google.com在iframe?](https://stackoverflow.com/questions/8700636/how -go-show-google-com-in-an-iframe) – Ridderhoff

+0

我的问题稍有不同。我试图找出一种方法,以便我可以了解是否可以在我的网页上显示特定的网站。 – MKR

回答

1

许多网站发送一个“X-Frame-Options:SAMEORIGIN”响应标题,它可以防止你在iframe中显示它们。此选项可防止浏览器显示与父页面不在同一域中的iframe。这是防止点击顶起的安全功能。 see more

做完我自己的测试后,我假设你在w3school的tryit.asp编辑器中测试,这就是为什么w3schools工作,但其他人没有。

此外,w3.org不会发送“x-frame-options:SAMEORIGIN”,这就是为什么它可以从其他域运行。

这里的表示,其防止从iframe中示出 here's an image showing the error which prevents the iframe from showing

+0

是的,我正在使用w3school的tryit。但它甚至可以在https://www.w3.org/和https://therunningbug.com/上使用同一个tryit页面。 – MKR

+1

编辑了我的答案,w3.org不会发送相同的原始标题,而且我猜测therunningbug.com也不会。 – Ridderhoff

+0

有没有办法找到哪个网站已经将'X-Frame-Options'设置为'sameorigin'? – MKR