[英]Change color of a SVG in Favicon
我想更改在 HTML 頁面中用作 FavIcon 的 SVG 的顏色。 我想使用一個按鈕,如果您單擊該按鈕,它應該會更改 FavIcon。
我已經讓它與我頁面上的普通 SVG 元素一起工作,但我找不到適用於 FavIcon 的方法。
有人知道怎么做嗎?
<link id="favicon" rel="icon" href="image-name.svg" type="image/png" sizes="16x16">
創建兩個圖標並使用 js 函數替換。
<button class="btn2" type="button" onclick="changeFavicon()"> Change Favicon </button>
// Assign a constant variable and get them by the favicon Id
const favicon = document.getElementById("favicon");
// Creating a function for the button
function changeFavicon() {
favicon.setAttribute("href", "image-name2.svg");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.