Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Chrome tab color with JavaScript or jQuery

In Chrome you can set the color of a tab with the meta tag:

<meta name="theme-color" content="#FFA000">

In my website, I have several sections color-coded. To make it look better, I would like to dynamically change the tab's color according to the currently opened section. I have tried doing it with jQuery:

$("meta[name='theme-color']").attr('content', '#455A64');

But it doesn't work. I would be very glad if someone can tell me if/how you can change this meta value during runtime.

Edit: After some checks I noticed that the code does change the meta tag content, but Chrome doesn't update the tab color.

like image 491
Sir_baaron Avatar asked Aug 28 '15 11:08

Sir_baaron


1 Answers

For this who land on this page from Google looking for a vanilla JS solution:

document.querySelector('meta[name="theme-color"]').setAttribute('content',  '#123456');
like image 188
WyriHaximus Avatar answered Sep 19 '22 16:09

WyriHaximus