[英]How do you add a badge to a website's bookmark icon?
例如,在 chrome 上,WhatsApp Web 書簽圖標顯示您當前的消息數,Reddit 有一個紅點,甚至當您有通知時,LinkedIn 也會在左上角顯示一個帶有藍點的圖標。 將不勝感激關於如何實現這一目標的正確方向。
可以通過更改 favicon 的 href 來動態更改收藏夾的圖標。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic favicon</title>
<link rel="icon" id="favicon" href="./icons/icon_without_dot.png" type="image/png" />
</head>
<body>
<h1>Dynamic favicon</h1>
<button onclick="toggleFavicon()">Change favicon</button>
<script>
const favicon = document.getElementById("favicon");
function toggleFavicon() {
if (favicon.getAttribute("href") == "./icons/icon_without_dot.png") {
favicon.setAttribute("href", "./icons/icon_with_dot.png");
}else{
favicon.setAttribute("href", "./icons/icon_without_dot.png")
}
}
</script>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.