【问题标题】:Alternative for absolute url when loading assets (Insecure resource )加载资产时替代绝对 url (不安全资源)
【发布时间】:2018-03-27 23:48:54
【问题描述】:

我在 Twig 模板文件中有一个 iframe,它显示了如下所示的 PDF 文件的内容:

<iframe src="https://docs.google.com/gview?url={{ absolute_url(asset('bundles/path/to/file.pdf')) }}&embedded=true"></iframe>

但在打开 iframe 时,Chrome 会显示以下错误消息:

混合内容:“https://website.com/home#pdf”处的页面通过 HTTPS 加载,但请求了不安全的资源“http://docs.google.com/gview?url=pdf/url?v2249&embedded=true”。此请求已被阻止;内容必须通过 HTTPS 提供。

我还能使用什么其他选项?

【问题讨论】:

    标签: symfony twig


    【解决方案1】:

    你可以使用

    {{ app.request.scheme ~'://' ~ app.request.httpHost ~ asset('bundles/path/to/file.pdf') }}
    

    首选选项是

    {{ app.request.getSchemeAndHttpHost() ~ asset('bundles/path/to/file.pdf') }}
    

    所以现成的解决方案如下:

    <iframe src="https://docs.google.com/gview?url={{ app.request.getSchemeAndHttpHost() ~ asset('bundles/path/to/file.pdf') }}&embedded=true"></iframe>
    

    【讨论】:

    • 这部分怎么样:https://docs.google.com/gview?url=?我要把它放在{{}} 之前吗?
    • 这仍然给了我一个GET http://localhost:35729/livereload.js net::ERR_CONNECTION_REFUSED,在 iframe 中,我收到一条“没有预览可用”的消息
    • 什么是 iframe 中生成的 URL?
    猜你喜欢
    • 2021-06-01
    • 2015-12-15
    • 1970-01-01
    • 2020-04-26
    • 2015-09-26
    • 2015-12-04
    • 1970-01-01
    • 2014-05-20
    • 2022-10-30
    相关资源
    最近更新 更多