如何阻止网站在iframe中加载? [英] how to block website from loading in iframe?

查看:1389
本文介绍了如何阻止网站在iframe中加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我尝试在iframe中加载youtube网站,但我检查了它没有工作。我使用了这个简单的代码。

 <!DOCTYPE html> 
< html>
< head>
< title>< / title>
< / head>
< body>
< iframe width =1000pxheight =700pxsrc =http://www.youtube.com>< / iframe>
< / body>
< / html>




  1. 我想知道,为什么我的网页不能在
    iframe中加载youtube网站..


  2. 我如何在我的网站中使用相同的技术,因此没有人可以在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>

  1. i want to know , why my webpage can't load youtube website in iframe..

  2. what code i use to load the youtube website in my webpage.

  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆