[英]iframe showing up blank
Your code is right, it's w3schools.com that's the problem. 你的代码是对的,这是w3schools.com的问题。 Opening up the developer console reveals this: 打开开发人员控制台会发现:
Refused to display 'https://www.w3schools.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
This means that w3schools.com will only work in a frame when the "origin" (the website your frame is on) is from w3schools.com. 这意味着当“起源”(您的框架所在的网站)来自w3schools.com时,w3schools.com将仅在框架中工作。 Otherwise, you'll just get a blank frame. 否则,你只会得到一个空白框架。
Pages from W3Schools are not displayed in iframe
elements from different server because the W3Schools site implements an iframe blocking policy. W3Schools的页面不会显示在来自不同服务器的iframe
元素中,因为W3Schools站点实现了iframe阻止策略。 In order to do this, it uses the X-Frame-Options
. 为此,它使用X-Frame-Options
。 (See also how to block website from loading in iframe? .) (另请参阅如何阻止网站加载iframe? )
You can check whether a site implements this policy by inspecting its HTTP headers. 您可以通过检查其HTTP标头来检查站点是否实现此策略。 For example, in Firefox, press F12
to open the inspection tools, then go to Network , select one of the objects that were sent over HTTP and look at the headers (or filter the headers for eg "x-frame"). 例如,在Firefox中,按F12
打开检查工具,然后转到网络 ,选择通过HTTP发送的一个对象并查看标题(或过滤标题,例如“x-frame”)。 Below is what this looks like for W3Schools: 以下是W3Schools的相似之处:
Notice x-frame-options: SAMEORIGIN in the lower right part of the screenshot. 注意x-frame-options:截图右下方的SAMEORIGIN 。 With x-frame-options: SAMEORIGIN
(or on some other sites x-frame-options: DENY
) set on the server side, you will not be able to load pages from that site inside an iframe
or a frame
. 使用x-frame-options: SAMEORIGIN
在服务器端设置x-frame-options: SAMEORIGIN
(或在其他一些网站上使用x-frame-options: DENY
),您将无法在iframe
或frame
内加载该网站的页面。
For more background, see X-Frame-Options – How to Combat Clickjacking , which also explains other values that can be used in the x-frame-options
header. 有关更多背景信息,请参阅X-Frame-Options - 如何对抗Clickjacking ,它还解释了可在x-frame-options
标头中使用的其他值。
If you want to test with a webpage from a server that does not block loading in iframes, try for example https://wiki.archlinux.org/ . 如果您想使用不阻止iframe加载的服务器测试网页,请尝试https://wiki.archlinux.org/ 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.