无法使用Safari中的javascript更改收藏图标

问题描述

我有一个页面可通过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>

有人可以在这里发现我在做什么错吗?

解决方法

似乎甚至不可能像this webkit issue中简单提到的那样。

引用:

...因为我们故意不允许对网站图标进行动态更改/动画...