iframe不显示主要网站的任何内容

时间:2017-07-29 19:36:34

标签: html security 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

1 个答案:

答案 0 :(得分:1)

许多网站都发送了一个&#34; X-Frame-Options:SAMEORIGIN&#34;响应标头,阻止您在iframe中显示它们。此选项可防止浏览器显示未与父页面位于同一域中的iframe。这是一种防止点击操作的安全功能。 see more

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

另外,w3.org并没有发送&#34; x-frame-options:SAMEORIGIN&#34;这就是为什么它适用于其他领域。

这是显示阻止iframe显示的错误的图片 here's an image showing the error which prevents the iframe from showing