文章目录
- 代码实现
html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1" />
<meta name="viewport" content="width=device-width" />
<!-- 网站logo设置 -->
<link rel="icon" href="/logo_two.svg" type="image/svg+xml" />
<title>网站名称</title>
<script>
function setFavicon(href) {
var link = document.querySelector("link[rel~='icon']");
link.href = href;
}
// 根据不同的域名设置不同的favicon
if (window.location.hostname.startsWith('one')) {
setFavicon('/logo_one.png');
} else {
setFavicon('/logo_two.svg');
}
</script>
</head>
<body>
<div id="app-container"></div>
</body>
</html>