无法在 safari 中使用 javascript 更改网站图标 [英] Can't change favicon with javascript in safari
本文介绍了无法在 safari 中使用 javascript 更改网站图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个通过 javascript 更改网站图标的页面.这在 chrome 和 firefox 上效果很好,但在 Safari 上它不起作用.我什至添加了 <link rel="apple-touch-icon";href="favicon-1.png">
部分并通过 javascript 对其进行了更改,但这也不起作用.
I have a page that changes the favicon through javascript. This works great on chrome and firefox, but on Safari it does not work. I even added the <link rel="apple-touch-icon" href="favicon-1.png">
part and changed that through javascript as well, but that also does not do the trick.
页面如下所示:
<html lang="en">
<head>
<meta charset="utf-8">
<title>Foo</title>
<link rel="icon" type="image/png" href="favicon-1.png">
<link rel="apple-touch-icon" href="favicon-1.png">
<style>
</style>
</head>
<body></body>
<script>
setTimeout(() => {
var favicon = document.querySelector('link[rel="icon"]');
var appleTouchIcon = document.querySelector('link[rel="apple-touch-icon"]');
favicon.setAttribute('type', 'image/png');
favicon.setAttribute('href', 'favicon-2.png');
appleTouchIcon.setAttribute('href', 'favicon-2.png');
}, 4000);
</script>
</body>
</html>
谁能发现我在这里做错了什么?
Can anyone spot what I am doing wrong here?
推荐答案
引用:
...因为我们故意不允许对网站图标进行动态更改/动画...
...Since we quite purposefully don't allow dynamic changes/animations to the favicon...
这篇关于无法在 safari 中使用 javascript 更改网站图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文