【问题标题】:Favicon icon is not displaying in IE browser for Angular 6 <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">Favicon 图标未在 IE 浏览器中显示 Angular 6 <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
【发布时间】:2019-12-31 11:44:52
【问题描述】:

我正在使用 Angular 6 项目。在 Index.html 中添加了一个链接,用于存储在根文件夹中的网站图标和图像。

rel="shortcut icon" type="image/x-icon" href="favicon.ico"

它在其他浏览器中显示,但在 IE 浏览器中看不到 favicon 图标。尝试添加

rel="shortcut icon" type="image/x-icon" href="/favicon.ico"

但看不到。然后尝试了

rel="shortcut icon" type="image/x-icon" href="{{baseUrl}}/favicon.ico"

如果我添加带有它显示的网站图标的基本 URL,但前提是我刷新页面。如果我重定向到另一个新页面,它不会显示,如果我刷新然后显示。不知道为什么会这样。它仅与Angular或其他有关吗?请尝试提供帮助。

【问题讨论】:

标签: internet-explorer angular6 favicon


【解决方案1】:

我在我的 Angular 应用程序中使用了以下代码,它运行良好,请检查它。

index.html 页面中的代码:

  <base href="/">
  <link rel="icon" type="image/x-icon" href="favicon.ico">

位于 src 文件夹中的 favicon.ico。我在 angular.json 文件(构建和测试节点)的资产节点中添加了 favicon.ico 路径。

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "augular6-sample": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/augular6-sample",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"              
            ],
            "styles": [
              "./node_modules/bootstrap/dist/css/bootstrap.min.css",
              "src/styles.css"
            ],
            "scripts": ["node_modules/jquery/dist/jquery.min.js"]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "augular6-sample:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "augular6-sample:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "augular6-sample:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.css"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },

编辑

此外,您还可以尝试在 assets 文件夹中添加图片,然后尝试使用以下代码:

  <link rel="icon" type="image/x-icon" href="./assets/Capture.PNG">

【讨论】:

  • 非常感谢您的回复。但这对我来说根本不起作用,我已经尝试过了。它只是显示 IE 图标。
  • 尝试清除浏览器缓存和cookie,然后重新检查是否正常。
  • 另外,您也可以尝试在assets文件夹中添加图片,然后尝试使用以下代码:&lt;link rel="icon" type="image/x-icon" href="./assets/Capture.PNG"&gt;
猜你喜欢
  • 2011-10-02
  • 2012-10-24
  • 1970-01-01
  • 1970-01-01
  • 2020-06-17
  • 1970-01-01
  • 1970-01-01
  • 2021-11-05
相关资源
最近更新 更多