【问题标题】:Content disposition link conflict内容配置链接冲突
【发布时间】:2015-07-07 21:12:56
【问题描述】:

我使用 MODx Evolution,并在我的 htaccess 文件中包含以下内容:

<IfModule mod_headers.c>
    <FilesMatch "\.jpg$">
      Header append Content-Disposition "attachment;"
    </FilesMatch>

    <FilesMatch "\.jpeg$">
      Header append Content-Disposition "attachment;"
    </FilesMatch>

    <FilesMatch "\.png$">
      Header append Content-Disposition "attachment;"
    </FilesMatch>
</IfModule>

我为每个可以下载的图像都有一个下载按钮,如下所示:

<div class="box download-box">
                        <a class="button" href="[*template-variable-image*]">Download</a>

以上代码完美运行。

现在我添加了另一个按钮,用户可以使用以下代码在单独的浏览器选项卡中查看完整的图像:

<h2 class="thumb-caption"><span data-href="[*template-variable-image*]" target="_blank">PREVIEW</span></h2>

现在,当用户单击“预览”时,会出现内容配置附件框以供下载。我怎样才能让“预览”以我计划的方式而不是内容下载框显示图像的预览???

【问题讨论】:

    标签: .htaccess modx content-disposition modx-evolution


    【解决方案1】:

    这更像是一个 HTML 而不是 MODX 问题。很多现代浏览器都知道 a 标签中的download attribute

    所以扔掉 .htaccess 添加并使用

    <a class="button" href="[*template-variable-image*]" download>Download</a>
    

    您也可以为此使用 javascript 并捕获所有浏览器。 John Culviner 为此编写了一个不错的 jQuery 插件 jquery-file-download

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-12
      • 2020-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-16
      相关资源
      最近更新 更多