【发布时间】:2017-02-10 10:33:06
【问题描述】:
我有一些链接,单击时会显示 PDF 文件。从笔记本电脑查看时链接有效,但当我在任何移动设备上尝试时(我尝试过 iPhone6、galaxy s6 和华为 p9),链接不起作用.我可以点击它,但仅此而已。
<a href="http://localhost/mlndemo/sites/default/files/2017-02/voorbeeld_sollicitatiebrief_0.pdf" type="application/pdf; length=420819" title="voorbeeld_sollicitatiebrief.pdf">Bekijk hier de volledige vacature</a>
如果有人可以帮助我解释为什么这不适用于移动设备,那就太好了:) 提前感谢您的帮助
编辑: 在使 target_blank 的 drupal 站点上找到此代码。这似乎有效,因为它现在在新窗口中打开文件。我会在这里发布代码只是为了有人可能需要它。 这仅适用于 Drupal (8) 将 THEME 更改为您的主题名称。
/**
* Implements hook_preprocess_HOOK().
*/
function THEME_preprocess_file_link(&$variables) {
// Add target _blank attribute to all file links.
$file = $variables['file'];
$url = file_create_url($file->uri->value);
// Use the description as the link text if available.
if (empty($variables['description'])) {
$link_text = $file->filename->value;
}
else {
$link_text = $variables['description']->__toString();
}
$link = '<a href="'.$url.'" type="'.$file->filemime->value . '" length="' . $file->filesize->value . '" title="' . \Drupal\Component\Utility\Html::escape($file->filename->value) . '" target="_blank">' . \Drupal\Component\Utility\Html::escape($link_text) . '</a>';
$variables['link']->setGeneratedLink($link);
}
【问题讨论】:
-
可能没有对 PDF 的内置支持
-
谢谢,去看看!