如何阻止网站在iframe中加载? [英] how to block website from loading in iframe?
问题描述
最近我尝试在iframe中加载youtube网站,但我检查了它没有工作。我使用了这个简单的代码。
<!DOCTYPE html>
< html>
< head>
< title>< / title>
< / head>
< body>
< iframe width =1000pxheight =700pxsrc =http://www.youtube.com>< / iframe>
< / body>
< / html>
-
我想知道,为什么我的网页不能在
iframe中加载youtube网站.. -
我如何在我的网站中使用相同的技术,因此没有人可以在iframe中添加我的网站
。
对于现代浏览器,需要在标题中启用 X-Frame-Options ,
x-框选项标题可以通过Web服务器配置设置来实现。
您可以在标题中查看 X-Frame-Options ,如下图所示:
参考: https://www.keycdn.com/blog/x-frame-options/
如果您的浏览器不支持它,那么您将拥有NO clickjacking防御,并可以使用HTTP Header Field X-Frame-Options,
< meta http-equiv =X- Frame-Optionscontent =deny>
X-Frame-Options有三种可能的值:
DENY -
无论站点是否尝试这样做,页面都不能显示在框架中。
SAMEORIGIN -
页面只能显示在与页面本身相同的框架中。
ALLOW-FROM uri -
页面只能显示在指定原点上的框架。
Recently i tried to load youtube website in an iframe, but i checked that it's not worked. i used this simple code.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<iframe width="1000px" height="700px" src="http://www.youtube.com" ></iframe>
</body>
</html>
i want to know , why my webpage can't load youtube website in iframe..
what code i use to load the youtube website in my webpage.
how i use same techniq in my website, so no one can add my website in iframe.
For modern browser, need to enable X-Frame-Options in Header, The x-frame-options header can be implement through web server configuration settings.
You can view the X-Frame-Options in Header as like below image,
Reference: https://www.keycdn.com/blog/x-frame-options/
If your browser does not support it, then you will have NO clickjacking defense in place and can use HTTP Header Field X-Frame-Options,
<meta http-equiv="X-Frame-Options" content="deny">
There are three possible values for X-Frame-Options:
DENY - The page cannot be displayed in a frame, regardless of the site attempting to do so.
SAMEORIGIN - The page can only be displayed in a frame on the same origin as the page itself.
ALLOW-FROM uri - The page can only be displayed in a frame on the specified origin.
这篇关于如何阻止网站在iframe中加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!