【问题标题】:Link not clickable for mobile手机无法点击链接
【发布时间】: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);
}

【问题讨论】:

标签: html css drupal href


【解决方案1】:

你最好试试这个:

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

应该可以。它将下载它,而不是直接下载它。希望它对你有用。我没有测试过。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-02
    • 2015-10-13
    • 1970-01-01
    • 2018-04-06
    • 2017-10-06
    • 2017-05-25
    • 1970-01-01
    相关资源
    最近更新 更多