【问题标题】:Viewing IFRAME independent of whether using HTTP or HTTPS独立于使用 HTTP 或 HTTPS 查看 IFRAME
【发布时间】:2014-11-30 14:15:28
【问题描述】:

假设我有以下 IFRAME。只要浏览器使用 HTTP 查看页面,它就可以正常工作,但是,如果浏览器使用 HTTPS 查看页面,则会导致错误,并且必须将 IFRAME 更改为也使用 HTTPS。

<iframe id="sitePreview" name="sitePreview" src="http://preview.administrator.test6.example.com/index.php?cid=17&amp;preview=1330668404"></iframe>

如果不使用服务器脚本根据用于查看页面的协议来自定义 HTML 的协议,是否可以创建 URI 以便它们同时使用 HTTP 和 HTTPS?

另外,如果这适用于其他链接,请发表评论,例如:

<img alt="Map" src="http://maps.google.com/maps/api/staticmap?markers=color:blue|31 Milk St Boston MA&amp;zoom=14&amp;size=400x400&amp;sensor=false" class="map">

<script src="http://maps.googleapis.com/maps/api/js?v=3.exp&amp;sensor=false&amp;libraries=places" type="text/javascript"></script>

【问题讨论】:

    标签: html http url iframe https


    【解决方案1】:

    请记住,跨站点 iframe 调用可能很棘手,请阅读这篇文章: http://blog.cakemail.com/the-iframe-cross-domain-policy-problem/,但是,由于它确实加载了,我假设您包含来自同一域的 iframe。

    要回答您的问题,只需将协议从 src 中删除,您可以将其引用为:

    <iframe id="sitePreview" name="sitePreview" src="//preview.administrator.test6.example.com/index.php?cid=17&amp;preview=1330668404"></iframe>
    

    这将确保它将使用父级使用的任何协议...

    您也可以将其硬编码为 https,但这意味着每个请求都将提供一个安全图像,这会产生不必要的开销...

    【讨论】:

    【解决方案2】:

    我认为这会起作用: 如果(位置 == “https://whatever.com”) { //这是https } 别的 { //这是http }

    如果我写的不对,请告诉我,我会重新编码。

    【讨论】:

    • 您提议的脚本在哪里运行服务器端(PHP 等)?
    • 它是 javascript,因此它应该在您需要知道它是 http 还是 https 的页面上运行。在我的 if 语句代码中,您可以添加所需的代码。因此,您可以将 document.write 添加到每个 if 并回显正确的 iframe。希望这对我在打电话时有所帮助,所以我的回答很简短。
    猜你喜欢
    • 2013-07-29
    • 2011-06-03
    • 2011-03-09
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 1970-01-01
    • 2017-09-06
    相关资源
    最近更新 更多