Fixing favicon changes on other browsers (#1017)
This commit is contained in:
parent
7bc168ad84
commit
83a45ae706
2 changed files with 17 additions and 7 deletions
|
@ -49,13 +49,19 @@ const MainApp = () => {
|
|||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const link = (document.querySelector("link[rel*='icon']") || document.createElement('link')) as HTMLLinkElement
|
||||
const oldLink = document.querySelector("link[rel*='icon']") as HTMLLinkElement
|
||||
if (!oldLink) {
|
||||
return () => null
|
||||
}
|
||||
|
||||
const restoreData = {
|
||||
type: link.type,
|
||||
rel: link.rel,
|
||||
href: link.href,
|
||||
type: oldLink.type,
|
||||
rel: oldLink.rel,
|
||||
href: oldLink.href,
|
||||
}
|
||||
return () => {
|
||||
document.querySelectorAll("link[rel*='icon']").forEach((n) => n.remove())
|
||||
const link = document.createElement('link') as HTMLLinkElement
|
||||
link.type = restoreData.type
|
||||
link.rel = restoreData.rel
|
||||
link.href = restoreData.href
|
||||
|
|
|
@ -241,11 +241,15 @@ class Utils {
|
|||
// favicon
|
||||
|
||||
static setFavicon(icon?: string): void {
|
||||
const href = icon ? `data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y=".9em" font-size="90">${icon}</text></svg>` : ''
|
||||
const link = (document.querySelector("link[rel*='icon']") || document.createElement('link')) as HTMLLinkElement
|
||||
if (!icon) {
|
||||
document.querySelector("link[rel*='icon']")?.remove()
|
||||
return
|
||||
}
|
||||
const link = document.createElement('link') as HTMLLinkElement
|
||||
link.type = 'image/x-icon'
|
||||
link.rel = 'shortcut icon'
|
||||
link.href = href
|
||||
link.href = `data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y=".9em" font-size="90">${icon}</text></svg>`
|
||||
document.querySelectorAll("link[rel*='icon']").forEach((n) => n.remove())
|
||||
document.getElementsByTagName('head')[0].appendChild(link)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue