使用js修改 theme-color 要考虑 meta 是否存在 不存在就添加上
可以通过以下代码实现:
// 获取 meta 标签
let meta = document.querySelector('meta[name="theme-color"]');
// 如果不存在,则创建新的 meta 标签
if (!meta) {
meta = document.createElement('meta');
meta.setAttribute('name', 'theme-color');
document.head.appendChild(meta);
}
// 修改 meta 标签的 content 属性
meta.setAttribute('content', '#000000'); // 可以替换成你想要的颜色值
原文地址: https://www.cveoy.top/t/topic/d9BG 著作权归作者所有。请勿转载和采集!