-
Notifications
You must be signed in to change notification settings - Fork 571
-
Notifications
You must be signed in to change notification settings - Fork 571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic theme switching #401
Comments
You can dispatch a custom event on theme change, then handle it with a function that will remove the previous DOM node and then load the script again with the new theme. https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events |
Thanks @tmshkr |
Happy to help @mrsauravsahu It would be ideal if the theme could be changed without having to reload the script. There seems to be a way to change the theme without reloading the script by using For example, if you execute the following code in your browser console, it should change the theme of the comments to dark:
But it only seems to work on utteranc.es or the utterances local dev environment. It doesn't seem to work on other sites. |
I can give it a try. |
Ah, the document
.querySelector("iframe.utterances-frame")
.contentWindow.postMessage(
{ type: "set-theme", theme: themeName },
"https://utteranc.es/"
) |
Oh that makes sense. There is a check on the origin |
Works great! Thanks @tmshkr |
That worked for me -- thanks @tmshkr |
I'm currently using utterances to add comments to my site. Sample is - https://mrsauravsahu.github.io/posts/39/ I have a theme toggle button in my navbar which allows to switch between light and dark themes. However, utterances loads directly when the page loads, so it does not respect the change in the theme attribute.
Is there a way to dynamically switch themes?
The text was updated successfully, but these errors were encountered: