【问题标题】:Can't change favicon with javascript in safari无法在 Safari 中使用 javascript 更改网站图标
【发布时间】:2020-09-07 17:34:29
【问题描述】:

我有一个通过 javascript 更改网站图标的页面。这在 chrome 和 firefox 上效果很好,但在 Safari 上它不起作用。我什至添加了 <link rel="apple-touch-icon" href="favicon-1.png"> 部分并通过 javascript 对其进行了更改,但这也不起作用。

页面如下所示:

<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>

谁能发现我在这里做错了什么?

【问题讨论】:

    标签: javascript html css safari favicon


    【解决方案1】:

    this webkit issue 中简要提到的似乎甚至不可能。

    引用:

    ...因为我们非常有目的地不允许对网站图标进行动态更改/动画...

    【讨论】:

      猜你喜欢
      • 2012-07-24
      • 2011-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-20
      相关资源
      最近更新 更多