Is it possible to dynamically set the background color of the :root CSS property in an HTML file based on a hash present in the URL? The code provided does change the background color, but unfortunately, the hash value doesn't persist as users navigate between different pages on the site. One potential solution could be to use CSSStyleSheet.insertRule() to ensure that the CSS changes stay applied throughout the user's session, especially since all pages are using the same stylesheet. However, implementing this function correctly might require some additional guidance.
<script>
if (window.location.hash) {
document.documentElement.style.setProperty(
'--main-bg-color',
window.location.hash
)
}
</script>