链接无法点击移动设备

时间:2017-02-10 10:33:06

标签: html css drupal href

我有一些链接,当点击时会显示一个PDF文件。链接在从笔记本电脑查看但我在任何移动设备上尝试时(我试过iPhone6,galaxy s6和huawei p9)链接没有做任何事情。我可以点击它,但那就是它。

enter image description here

<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>

如果有人能帮助我解决为什么这不适用于那些会很棒的移动设备:)提前感谢您的帮助

编辑: 在drupal站点上找到了生成target_blank的代码。这似乎有效,因为它现在在新窗口中打开文件。我在这里发布代码只是为了有人可能需要它。 这仅适用于Drupal(8)将主题更改为您的名字。

/**
 * 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);
}

1 个答案:

答案 0 :(得分:0)

你可能最好试试这个:

<a href="http://localhost/mlndemo/sites/default/files/2017-02/voorbeeld_sollicitatiebrief_0.pdf" title="voorbeeld_sollicitatiebrief.pdf" download>Bekijk hier de volledige vacature</a>

那应该有用。它会下载它,而不是直接下载它。希望它适合你。我还没有测试过它。