当页面更改时,为什么要在IE11中动态设置图标消失?



我正在使用角度5.2.11。我有一个品牌服务,它将不同的URL发送到网站图标到应用程序。当页面像这样加载时,我正在设置图标:

const favicon = document.createElement('link');
favicon.setAttribute('type', 'image/x-icon');
favicon.setAttribute('rel', 'icon');
favicon.setAttribute('href', '//someUrlWherePlacedFavicon');
document.head.appendChild(favicon);

在IE11中,当使用路由服务更改页面时,网站图标是从站点"/favicon.ico"的根目录设置的。甚至从控制台更改不起作用。但是,如果页面重新加载,则图标将开始正常更改。

每次更改页面时,我都尝试替换图标链接,但它不起作用。 我想这是角度路由或IE11的错误。思潮?

您可以使用组件内的 DOCUMENT 类实现设置动态收藏夹图标链接。

在索引中.html设置链接标记

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

并在代码导入中的某个位置

import { Component, Inject } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
constructor(@Inject(DOCUMENT) private _document: HTMLDocument) {}
this._document.getElementById('appFavicon').setAttribute('href', '/your/icon/path.ico');

最新更新