html - 如何在 https 站点的 iframe 中允许 http 内容

标签 html security http iframe https

我将一些 HTML 加载到 iframe 中,但是当引用的文件使用的是 http 而不是 https 时,我收到以下错误:

[blocked] The page at {current_pagename} ran insecure content from {referenced_filename}

有什么方法可以关闭它或绕过它吗?

iframe 没有 src 属性,内容使用:

frame.open();
frame.write(html);
frame.close();

最佳答案

Note: While this solution may have worked in some browsers when it was written in 2014, it no longer works. Navigating or redirecting to an HTTP URL in an iframe embedded in an HTTPS page is not permitted by modern browsers, even if the frame started out with an HTTPS URL.

我创建的最佳解决方案是简单地使用 google 作为 ssl 代理...

https://www.google.com/search?q=%http://yourhttpsite.com&btnI=Im+Feeling+Lucky

在 Firefox 中测试和工作。

其他方法:

  • 使用第三方,例如 embed.ly(但它实际上只适用于众所周知的 http API)。

  • 在您控制的 https 页面上创建您自己的重定向脚本(相对链接页面上的简单 javascript 重定向应该可以解决问题。类似于:(您可以使用任何语言/方法)

    https://example.com 有一个 iframe 链接到...

    https://example.com/utilities/redirect.html 它有一个简单的 js 重定向脚本,例如...

    document.location.href ="http://thenonsslsite.com";

  • 或者,您可以添加 RSS 提要或编写一些阅读器/解析器来读取 http 站点并将其显示在您的 https 站点中。

  • 您还可以/应该向 http 站点所有者推荐他们创建 ssl 连接。如果没有其他原因而不是 it increases seo .

除非您可以让 http 站点所有者创建 ssl 证书,否则最安全和永久的解决方案是创建一个 RSS 提要来获取您需要的内容(大概您实际上并没有在 http 站点上“做”任何事情 -也就是说不登录任何系统)。

真正的问题是在 https 站点中包含 http 元素代表了安全问题。没有完全解决此安全风险的方法,因此以上只是当前的解决方法。

请注意,您可以在大多数浏览器中禁用此安全措施(您自己,而不是其他人)。另请注意,这些“黑客”可能会随着时间的推移而过时。

关于html - 如何在 https 站点的 iframe 中允许 http 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18327314/

相关文章:

javascript - 通过具有http auth的ajax获取外部网页的特定部分

javascript - append Div 到受尊重的 td th

java - 如何保护 Class.forName("com.mysql.jdbc.Driver)?

http - Jboss AS7 session 超时配置

HTML 电子邮件多个 cid 引用不显示在 hotmail 上

html - Angularjs 重复不显示空间

java - 确保休息端点安全的框架/库/模式

c - 使 C 免受缓冲区溢出和其他错误影响的选项?

java - 如何使用 RSA 加密对 http 响应进行加密

ruby-on-rails - Google Geocoding API request_denied