【问题标题】:<iframe> is not working<iframe> 不工作
【发布时间】:2016-04-02 11:51:24
【问题描述】:

我正在制作一个简单的 html 页面,它需要 &lt;iframe&gt; 来显示页面的特定区域。我用了很多次iframe,但这次我不知道我做错了什么......

请看一下我的代码并帮助我!

HTML

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Iframe Test</title>
</head>
<body>
    <iframe src="https://www.secure-booker.com/sorelle/ShopOnline/Products.aspx" width="1000" height="1000" frameborder="0"></iframe>
</body>
</html>

【问题讨论】:

  • “不工作”是什么意思?
  • IS NOT WORKING 意味着 iframe 不工作并且什么也没有显示...
  • 它被 X-FRAME-OPTIONS 阻止。参考我的答案!

标签: html iframe


【解决方案1】:

您尝试嵌入 iframe 的页面会阻止其自身被嵌入。

如果您打开浏览器的控制台 (F12) 并选择“控制台”选项卡,您可以看到这一点。

Refused to display 'https://www.secure-booker.com/sorelle/ShopOnline/Products.aspx' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self' http://*.sorellechicago.com sorellechicago.com *.sorellechicago.com".

TL;DR:这是不可能的。

【讨论】:

  • 有什么替代方法吗?
  • 不。从来没听说过。对不起。
  • 虽然尝试谷歌搜索“规避 xframe 选项”,你会发现这样的文章:blog.elev.io/… 虽然我不能声称已经阅读过它。
  • 没有用,杰克,但感谢您提供的信息和知识:)
  • 是的,可惜……但至少我知道了一件新事物……杰克 TL;DR 是什么意思?
【解决方案2】:

您不得对本网站进行 iFrame。因为他们设置了以下内容。

“X-Frame-Options”到“SAMEORIGIN”。

您可以从控制台中找到它。

拒绝在框架中显示“https://www.secure-booker.com/sorelle/ShopOnline/Products.aspx”,因为祖先违反了以下内容安全策略指令:“frame-ancestors 'self' http://*.sorellechicago.com sorellechicago.com *.sorellechicago.com” .

如何设置这个选项?

  1. https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options
  2. How to set 'X-Frame-Options' on iframe?
  3. X-Frame-Options on apache

另一个注意事项(FYI):AFAIK,还有一件事叫做Frame Buster Code,以防止其他域对网站进行iFrame。以下是参考网址:

  1. https://en.wikipedia.org/wiki/Framekiller
  2. https://davidwalsh.name/javascript-framebuster
  3. Frame Buster Buster ... buster code needed

它也是Clickjacking 的一部分。也请参考以下网址。 1.https://en.wikipedia.org/wiki/Clickjacking

【讨论】:

    猜你喜欢
    • 2017-12-15
    • 1970-01-01
    • 2011-09-23
    • 2015-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多