My website provides the dark mode button, so when button was click, I need to change the color theme of Dicourse Embeds to keep the same with my website.
But when I try to add class for body of embedded iframe, I found iframe.contentDocument
is always null, and if use document.getElementById("discourse-embed-frame").contentWindow.document
, the error as below:
I think there should be a way to config the embedded frame to allow cross-origin, but I still not found how to config after trying some config.
The other way maybe to use postMessage
, like document.getElementById("discourse-embed-frame").contentWindow.postMessage("darkMode")
, but there needs to be an handler to handle the darkMode
message in script, I haven’t found where to add it.