我不确定这是否可能;我们有各种主题颜色(颜色.)每一页都会有变化。我们还使用了许多内容加载,没有页面刷新。
我想使用在铬移动浏览器中可用的主题颜色元标签来设置选项卡颜色。
由于我们的网页不刷新,我想这个颜色反映新的页面背景颜色。我可以删除原来的元,并添加一个新的与以下;
function updateMetaThemeColor(theme) {
var themeColor;
if(theme == 'theme-1') {
themeColor = '#f4dcdc'
} else if(theme == 'theme-2') {
themeColor = '#f0e8dd';
} else if(theme == 'theme-3') {
themeColor = '#d5e7f0';
} else if(theme == 'theme-4') {
themeColor = '#f6efb9';
} else if(theme == 'theme-5') {
themeColor = '#eaeae8';
} else if(theme == 'theme-6') {
themeColor = '#f8e3c7';
} else if(theme == 'theme-7') {
themeColor = '#cde8e8';
}
//remove the current meta
$('meta[name=theme-color]').remove();
//add the new one
$('head').append('<meta name="theme-color" content="'+themeColor+'">');
}这是可行的,因为它移除并重新构造元标记,但正如我所担心的,这种更改没有反映在Chrome移动浏览器上的页面本身。
是否有办法迫使移动浏览器重新查找元标记,并在必要时进行更改?
谢谢
发布于 2015-09-08 13:46:09
实际上,上面的方法确实是按照它应有的方式工作的。我想我应该考得更好,嗯。
发布于 2021-11-09 03:05:27
你可以这样做
document.querySelector("meta[name='theme-color']").setAttribute("content", "<your-color>");或
document.querySelector("meta[name='theme-color']").content = "<your-color>";https://stackoverflow.com/questions/32330305
复制相似问题