Html 显示 PDF 文件的图标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4886423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 06:29:45  来源:igfitidea点击:

Display favicon for PDF files

htmlfavicon

提问by Jinesh

I am working on a Drupal site with some PDF files where I am opening a PDF file in a new window. The files are getting opened in the browser with the Acrobat Reader plugin but the favicon is not getting displayed. What should be done to show the favicon?

我正在使用一些 PDF 文件在 Drupal 站点上工作,我在新窗口中打开一个 PDF 文件。使用 Acrobat Reader 插件在浏览器中打开文件,但未显示收藏夹图标。应该怎么做才能显示网站图标?

采纳答案by Pekka

If you show the PDF file in an iframe, the browser should show the site-wide favicon, but you're out of luck in an external applications. Acrobat Reader doesn't use Favicons.

如果您在 .pdf 文件中显示 PDF 文件iframe,则浏览器应显示站点范围的图标,但在外部应用程序中您就不走运了。Acrobat Reader 不使用 Favicon。

UPDATEThis is now possible by placing favicon.ico in the root directory of your website as per @s1m0n1stv4n answer below

更新现在可以按照下面的@s1m0n1stv4n 答案将 favicon.ico 放在您网站的根目录中

回答by s1m0n1stv4n

If you put a favicon.icoto the root of your site, then your PDFs opened on that site will actually have that favicon. You can generate transparent ICOs from PNGs with online favicon genereators.

如果您将 a 放在favicon.ico您网站的根目录,那么您在该网站上打开的 PDF 实际上将具有该网站图标。您可以使用在线图标生成器从 PNG 生成透明的 ICO。

For example, if your favicon is reachable in:

例如,如果您的网站图标可通过以下方式访问:

http://example.com/favicon.ico

Then your PDF will show this favicon in the Acrobat plugin tab:

然后您的 PDF 将在 Acrobat 插件选项卡中显示此图标:

http://example.com/something/something.pdf

回答by RichardLynch

In the Drupal root directory, edit the .htaccessfile and add this:

在 Drupal 根目录中,编辑.htaccess文件并添加以下内容:

RewriteRule ^favicon.ico sites/%{SERVER_NAME}/favicon.ico [NC,L]

RewriteRule ^favicon.ico sites/%{SERVER_NAME}/favicon.ico [NC,L]

Exactly as it is typed there, and right after the RewriteBase line near the bottom.

与在那里输入的完全一样,就在靠近底部的 RewriteBase 行之后。

See caveats here: http://drupal.org/node/174940#comment-852888

请参阅此处的警告:http: //drupal.org/node/174940#comment-852888

This assumes you have friendly URLs working in Drupal, or the RewriteRule will be useless.

这假设您在 Drupal 中有友好的 URL,否则 RewriteRule 将无用。

In each sites/example.com/ directory, add the favicon.ico for that site.

在每个站点/example.com/ 目录中,添加该站点的 favicon.ico。

Jump through hoops to clear your favicon cache in your browser / OS: http://www.faviconblog.com/clear-the-browser-cache-to-display-your-favicon/

跳过箍以清除浏览器/操作系统中的网站图标缓存:http: //www.faviconblog.com/clear-the-browser-cache-to-display-your-favicon/

This MAY over-ride the HTML HEAD favicon that Drupal spits out when you upload one in some browsers, or not. Haven't tested. If it does, you'll have to have a favicon.ico for every sites/XYZ/

当您在某些浏览器中上传一个时,这可能会覆盖 Drupal 吐出的 HTML HEAD 图标。没测试过 如果是这样,您将必须为每个站点/XYZ/ 拥有一个 favicon.ico

Note that just because uploaded HEAD favicon overrides the sites/XYZ/ in one browser, is no indication it will work in another, or vice versa.

请注意,仅仅因为上传的 HEAD 图标覆盖了一个浏览器中的站点/XYZ/,并不表示它可以在另一个浏览器中工作,反之亦然。

回答by BillVo

Displaying the PDF from <iframe>, <object>, or maybe even <embed>tag inside of an HTML page should result in the favicon being used.

显示来自<iframe><object>或什<embed>至 HTML 页面内的标记的 PDF应该会导致使用收藏夹图标。